Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ class="valignmiddle inline-block linkobject hideobject"
$toggle->fieldOverride = ob_get_clean();
}

$formSetup->newItem('ADVANCED_SECTION_TITLE')->setAsTitle();

$thirdparty_field = $formSetup->newItem('AUTOVERIFACTU_THIRDPARTY_FOR_SELL')->setAsSelect(array());
$filter = '((s.client:IN:1,2,3) AND (s.status:=:1))';
$thirdparty_field->fieldOverride = img_picto('', 'company', 'class="pictfixedwidth"') . ' ' . $formSetup->form->select_company(getDolGlobalInt('AUTOVERIFACTU_THIRDPARTY_FOR_SELL'), 'socid', $filter, 1, 0, 0, array(), 0, 'maxwidth500 widthcentpercentminusx');

$setupnotempty += count($formSetup->items);

/*
Expand Down
2 changes: 1 addition & 1 deletion class/actions_autoverifactu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public function dolGetButtonAction(&$parameters, $object, $action)
if (
!$valid_id
&& !$thirdparty->tva_intra
&& !autoverifactuIsPosInvoice($object)
&& !autoverifactuIsSimplifiedInvoice($object)
&& !empty($parameters['userRight'])
) {
$label = $langs->trans('ThirdpartyIdProfRequired');
Expand Down
2 changes: 2 additions & 0 deletions langs/ca_ES/autoverifactu.lang
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ AUTOVERIFACTU_TAX = Tipus d'import
AUTOVERIFACTU_DATE_VALIDATION = És obligatori l'ús de a data de validació com a data d'emissió de les factures?
AUTOVERIFACTU_DATE_VALIDATIONTooltip = La data de les factures ha de coincidir amb la seva data de validació. Ves a Configuració > Mòduls > Factures per canviar el valor de la configuració.
AUTOVERIFACTU_BLOCKEDLOG_ENABLED = Està el mòdul BlockedLog habilitat?
AUTOVERIFACTU_THIRDPARTY_FOR_SELL = Client genèric
AUTOVERIFACTU_THIRDPARTY_FOR_SELLTooltip = Client genèric destinatari de les nostres factures simplificades. Ens permetrà emetre factures a un client sense NIF vàlid o conegut. En cas de no venir definit, no es podran emetre factures simplificaddes.
YouComanyName = Raó social
YourCompanyVat = NIF/CIF
PK12_PATH = ruta/al/teu/certificat.p12
Expand Down
2 changes: 2 additions & 0 deletions langs/en_US/autoverifactu.lang
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ AUTOVERIFACTU_TAX = Tax type
AUTOVERIFACTU_DATE_VALIDATION = Is invoice validation date mandatory?
AUTOVERIFACTU_DATE_VALIDATIONTooltip = Invoice date has to be set to the date when it's validated. Go to Setup > Modules > Invoice to change the setting value.
AUTOVERIFACTU_BLOCKEDLOG_ENABLED = Is BlockedLog module enabled?
AUTOVERIFACTU_THIRDPARTY_FOR_SELL = Generic customer
AUTOVERIFACTU_THIRDPARTY_FOR_SELLTooltip = Generic customer recipient of our simplified invoices. It will allow us to emit invoices to a costumer that does not have a vàlid or known ID. If it does not come defined, simplified invoices will be not allowed.
YouComanyName = Your company name
YourCompanyVat = Your company VAT number
PK12_PATH = path/to/your/certificate.p12
Expand Down
2 changes: 2 additions & 0 deletions langs/es_ES/autoverifactu.lang
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ AUTOVERIFACTU_TAX = Tipo de impuesto
AUTOVERIFACTU_DATE_VALIDATION = ¿Es obligatorio el uso de la fecha de valicación como fecha de emision de las facturas?
AUTOVERIFACTU_DATE_VALIDATIONTooltip = La fecha de las facturas ha de coincidir con su fecha de validación. Ve a Configuración > Módulos > Facturas para cambiar el valor de la configuración.
AUTOVERIFACTU_BLOCKEDLOG_ENABLED = ¿Esta el módulo BlockedLog habilitado?
AUTOVERIFACTU_THIRDPARTY_FOR_SELL = Cliente genérico
AUTOVERIFACTU_THIRDPARTY_FOR_SELLTooltip = Cliente genérico destinatario de nuestras facturas simplificadas. Nos permitirá emitir facturas a un cliente sin NIF válido o conocido. En caso de no venir definido, no se podran emitir facturas simplificadas.
YouComanyName = Razón social
YourCompanyVat = NIF/CIF
PK12_PATH = ruta/a/tu/certificado.p12
Expand Down
27 changes: 27 additions & 0 deletions lib/validation.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,33 @@ function autoverifactuIsInvoiceRecorded($invoice)
return (!empty($invoice->array_options['options_verifactu_hash']) && !in_array($invoice->array_options['options_verifactu_status'], array('2','4','5'), true));
}

/**
* Checks if an invoices is simplified. A simplified invoice is an invoice that
* has as thirdparty the generic customer identified by AUTOVERIFACTU_THIRDPARTY_FOR_SELL.
*
* @param Facture $invoice Target invoice.
*
* @return bool
*/
function autoverifactuIsSimplifiedInvoice($invoice)
{
$invoice->fetch_thirdparty();
$thirdparty = $invoice->thirdparty;
$valid_id = $thirdparty->id_prof_check(1, $thirdparty);

if ($valid_id || $thirdparty->tva_intra) {
return false;
}

$is_pos = autoverifactuIsPosInvoice($invoice);
if ($is_pos) {
return true;
}

$generic_customer_id = getDolGlobalInt('AUTOVERIFACTU_THIRDPARTY_FOR_SELL');
return $generic_customer_id == $thirdparty->id;
}

/**
* Checks if an invoices is a POS invoice, or a derived invoice from a POS invoice.
*
Expand Down
9 changes: 5 additions & 4 deletions lib/verifactu.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ function autoverifactuRegisterInvoice($invoice, $action)
$invoice->fetch_thirdparty();
$thirdparty = $invoice->thirdparty;
$valid_id = $thirdparty->id_prof_check(1, $thirdparty);
$is_simple = autoverifactuIsSimplifiedInvoice($invoice);

//las facturas simplificadas no tienen tercero y por tanto tienen que evitar esta validación
if (!autoverifactuIsPosInvoice($invoice) && $valid_id <= 0 && !$thirdparty->tva_intra) {
if ($valid_id <= 0 && !$thirdparty->tva_intra && !$is_simple) {
dol_syslog('Skip invoice verifactu record registration due to thirdparty without a vaid idprof1');
$invoice->error[] = 'NotNIFThirdparty';
return -1;
Expand Down Expand Up @@ -578,7 +579,7 @@ function autoverifactuInvoiceToRecord($invoice, $recordType = 'alta')
switch ($invoice->type) {
case Facture::TYPE_STANDARD:
case Facture::TYPE_DEPOSIT:
if (autoverifactuIsPosInvoice($invoice)) {
if (autoverifactuIsSimplifiedInvoice($invoice)) {
// Factura simplificada y facturas sin identificación del destinatario (Art. 6.1.D del R.D. 1619/2012).
$invoiceType = 'F2';
} else {
Expand All @@ -591,7 +592,7 @@ function autoverifactuInvoiceToRecord($invoice, $recordType = 'alta')
break;
case Facture::TYPE_REPLACEMENT:
case Facture::TYPE_CREDIT_NOTE:
if (autoverifactuIsPosInvoice($invoice)) {
if (autoverifactuIsSimplifiedInvoice($invoice)) {
// Factura rectificativa simplificada
$invoiceType = 'R5';
} else {
Expand Down Expand Up @@ -1258,7 +1259,7 @@ function autoverifactuRegisterInvoiceList($invoices)
$thirdparty = $invoice->thirdparty;
$valid_id = $thirdparty->id_prof_check(1, $thirdparty);

if (!autoverifactuIsPosInvoice($invoice) && $valid_id <= 0 && !$thirdparty->tva_intra) {
if ($valid_id <= 0 && !$thirdparty->tva_intra) {
dol_syslog('Skip invoice #' . $invoice->id . ' due to thirdparty without valid idprof1');
continue;
}
Expand Down
Loading