Fix vat npr for template invoices
This commit is contained in:
parent
4034122169
commit
57f664c0c1
@ -840,8 +840,8 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$object->date = $dateinvoice;
|
$object->date = $dateinvoice;
|
||||||
$object->date_pointoftax = $date_pointoftax;
|
$object->date_pointoftax = $date_pointoftax;
|
||||||
$object->note_public = trim($_POST['note_public']);
|
$object->note_public = trim(GETPOST('note_public','none'));
|
||||||
$object->note = trim($_POST['note']);
|
// We do not copy the private note
|
||||||
$object->ref_client = $_POST['ref_client'];
|
$object->ref_client = $_POST['ref_client'];
|
||||||
$object->ref_int = $_POST['ref_int'];
|
$object->ref_int = $_POST['ref_int'];
|
||||||
$object->modelpdf = $_POST['model'];
|
$object->modelpdf = $_POST['model'];
|
||||||
@ -892,8 +892,8 @@ if (empty($reshook))
|
|||||||
$object->number = $_POST['facnumber'];
|
$object->number = $_POST['facnumber'];
|
||||||
$object->date = $dateinvoice;
|
$object->date = $dateinvoice;
|
||||||
$object->date_pointoftax = $date_pointoftax;
|
$object->date_pointoftax = $date_pointoftax;
|
||||||
$object->note_public = trim($_POST['note_public']);
|
$object->note_public = trim(GETPOST('note_public','none'));
|
||||||
$object->note = trim($_POST['note']);
|
// We do not copy the private note
|
||||||
$object->ref_client = $_POST['ref_client'];
|
$object->ref_client = $_POST['ref_client'];
|
||||||
$object->ref_int = $_POST['ref_int'];
|
$object->ref_int = $_POST['ref_int'];
|
||||||
$object->modelpdf = $_POST['model'];
|
$object->modelpdf = $_POST['model'];
|
||||||
@ -994,8 +994,8 @@ if (empty($reshook))
|
|||||||
$object->number = $_POST['facnumber'];
|
$object->number = $_POST['facnumber'];
|
||||||
$object->date = $dateinvoice;
|
$object->date = $dateinvoice;
|
||||||
$object->date_pointoftax = $date_pointoftax;
|
$object->date_pointoftax = $date_pointoftax;
|
||||||
$object->note_public = trim($_POST['note_public']);
|
$object->note_public = trim(GETPOST('note_public','none'));
|
||||||
$object->note_private = trim($_POST['note_private']);
|
$object->note_private = trim(GETPOST('note_private','none'));
|
||||||
$object->ref_client = $_POST['ref_client'];
|
$object->ref_client = $_POST['ref_client'];
|
||||||
$object->ref_int = $_POST['ref_int'];
|
$object->ref_int = $_POST['ref_int'];
|
||||||
$object->modelpdf = $_POST['model'];
|
$object->modelpdf = $_POST['model'];
|
||||||
@ -1012,9 +1012,9 @@ if (empty($reshook))
|
|||||||
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
|
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
|
||||||
|
|
||||||
// Source facture
|
// Source facture
|
||||||
$object->fac_rec = GETPOST('fac_rec');
|
$object->fac_rec = GETPOST('fac_rec', 'int');
|
||||||
|
|
||||||
$id = $object->create($user); // This include recopy of links from recurring invoice
|
$id = $object->create($user); // This include recopy of links from recurring invoice and invoice lines
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1044,8 +1044,8 @@ if (empty($reshook))
|
|||||||
$object->number = $_POST['facnumber'];
|
$object->number = $_POST['facnumber'];
|
||||||
$object->date = $dateinvoice;
|
$object->date = $dateinvoice;
|
||||||
$object->date_pointoftax = $date_pointoftax;
|
$object->date_pointoftax = $date_pointoftax;
|
||||||
$object->note_public = trim($_POST['note_public']);
|
$object->note_public = trim(GETPOST('note_public','none'));
|
||||||
$object->note_private = trim($_POST['note_private']);
|
$object->note_private = trim(GETPOST('note_private','none'));
|
||||||
$object->ref_client = $_POST['ref_client'];
|
$object->ref_client = $_POST['ref_client'];
|
||||||
$object->ref_int = $_POST['ref_int'];
|
$object->ref_int = $_POST['ref_int'];
|
||||||
$object->modelpdf = $_POST['model'];
|
$object->modelpdf = $_POST['model'];
|
||||||
@ -1905,8 +1905,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
// Define info_bits
|
// Define info_bits
|
||||||
$info_bits = 0;
|
$info_bits = 0;
|
||||||
if (preg_match('/\*/', $vat_rate))
|
if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
|
||||||
$info_bits |= 0x01;
|
|
||||||
|
|
||||||
// Define vat_rate
|
// Define vat_rate
|
||||||
$vat_rate = str_replace('*', '', $vat_rate);
|
$vat_rate = str_replace('*', '', $vat_rate);
|
||||||
|
|||||||
@ -202,7 +202,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$facsrc->lines[$i]->fk_product,
|
$facsrc->lines[$i]->fk_product,
|
||||||
$facsrc->lines[$i]->remise_percent,
|
$facsrc->lines[$i]->remise_percent,
|
||||||
'HT',
|
'HT',
|
||||||
0,
|
$facsrc->lines[$i]->info_bits,
|
||||||
'',
|
'',
|
||||||
0,
|
0,
|
||||||
$facsrc->lines[$i]->product_type,
|
$facsrc->lines[$i]->product_type,
|
||||||
@ -596,7 +596,7 @@ class FactureRec extends CommonInvoice
|
|||||||
* @param int $fk_product Id du produit/service predefini
|
* @param int $fk_product Id du produit/service predefini
|
||||||
* @param double $remise_percent Pourcentage de remise de la ligne
|
* @param double $remise_percent Pourcentage de remise de la ligne
|
||||||
* @param string $price_base_type HT or TTC
|
* @param string $price_base_type HT or TTC
|
||||||
* @param int $info_bits Bits de type de lignes
|
* @param int $info_bits VAT npr or not ?
|
||||||
* @param int $fk_remise_except Id remise
|
* @param int $fk_remise_except Id remise
|
||||||
* @param double $pu_ttc Prix unitaire TTC (> 0 even for credit note)
|
* @param double $pu_ttc Prix unitaire TTC (> 0 even for credit note)
|
||||||
* @param int $type Type of line (0=product, 1=service)
|
* @param int $type Type of line (0=product, 1=service)
|
||||||
@ -635,7 +635,6 @@ class FactureRec extends CommonInvoice
|
|||||||
$remise_percent=price2num($remise_percent);
|
$remise_percent=price2num($remise_percent);
|
||||||
if (empty($remise_percent)) $remise_percent=0;
|
if (empty($remise_percent)) $remise_percent=0;
|
||||||
$qty=price2num($qty);
|
$qty=price2num($qty);
|
||||||
if (! $info_bits) $info_bits=0;
|
|
||||||
$pu_ht = price2num($pu_ht);
|
$pu_ht = price2num($pu_ht);
|
||||||
$pu_ttc = price2num($pu_ttc);
|
$pu_ttc = price2num($pu_ttc);
|
||||||
$txtva = price2num($txtva);
|
$txtva = price2num($txtva);
|
||||||
@ -644,6 +643,7 @@ class FactureRec extends CommonInvoice
|
|||||||
if (empty($txtva)) $txtva=0;
|
if (empty($txtva)) $txtva=0;
|
||||||
if (empty($txlocaltax1)) $txlocaltax1=0;
|
if (empty($txlocaltax1)) $txlocaltax1=0;
|
||||||
if (empty($txlocaltax2)) $txlocaltax2=0;
|
if (empty($txlocaltax2)) $txlocaltax2=0;
|
||||||
|
if (empty($info_bits)) $info_bits=0;
|
||||||
|
|
||||||
if ($price_base_type=='HT')
|
if ($price_base_type=='HT')
|
||||||
{
|
{
|
||||||
@ -703,6 +703,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$sql.= ", total_localtax1";
|
$sql.= ", total_localtax1";
|
||||||
$sql.= ", total_localtax2";
|
$sql.= ", total_localtax2";
|
||||||
$sql.= ", total_ttc";
|
$sql.= ", total_ttc";
|
||||||
|
$sql.= ", info_bits";
|
||||||
$sql.= ", rang";
|
$sql.= ", rang";
|
||||||
$sql.= ", special_code";
|
$sql.= ", special_code";
|
||||||
$sql.= ", fk_unit";
|
$sql.= ", fk_unit";
|
||||||
@ -729,6 +730,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$sql.= ", ".price2num($total_localtax1);
|
$sql.= ", ".price2num($total_localtax1);
|
||||||
$sql.= ", ".price2num($total_localtax2);
|
$sql.= ", ".price2num($total_localtax2);
|
||||||
$sql.= ", ".price2num($total_ttc);
|
$sql.= ", ".price2num($total_ttc);
|
||||||
|
$sql.= ", ".$info_bits;
|
||||||
$sql.= ", ".$rang;
|
$sql.= ", ".$rang;
|
||||||
$sql.= ", ".$special_code;
|
$sql.= ", ".$special_code;
|
||||||
$sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
|
$sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
|
||||||
@ -811,7 +813,7 @@ class FactureRec extends CommonInvoice
|
|||||||
// Clean parameters
|
// Clean parameters
|
||||||
$remise_percent=price2num($remise_percent);
|
$remise_percent=price2num($remise_percent);
|
||||||
$qty=price2num($qty);
|
$qty=price2num($qty);
|
||||||
if (! $info_bits) $info_bits=0;
|
if (empty($info_bits)) $info_bits=0;
|
||||||
$pu_ht=price2num($pu_ht);
|
$pu_ht=price2num($pu_ht);
|
||||||
$pu_ttc=price2num($pu_ttc);
|
$pu_ttc=price2num($pu_ttc);
|
||||||
$txtva=price2num($txtva);
|
$txtva=price2num($txtva);
|
||||||
@ -884,6 +886,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$sql.= ", total_localtax1='".price2num($total_localtax1)."'";
|
$sql.= ", total_localtax1='".price2num($total_localtax1)."'";
|
||||||
$sql.= ", total_localtax2='".price2num($total_localtax2)."'";
|
$sql.= ", total_localtax2='".price2num($total_localtax2)."'";
|
||||||
$sql.= ", total_ttc='".price2num($total_ttc)."'";
|
$sql.= ", total_ttc='".price2num($total_ttc)."'";
|
||||||
|
$sql.= ", info_bits=".$info_bits;
|
||||||
$sql.= ", rang=".$rang;
|
$sql.= ", rang=".$rang;
|
||||||
$sql.= ", special_code=".$special_code;
|
$sql.= ", special_code=".$special_code;
|
||||||
$sql.= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
|
$sql.= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
|
||||||
|
|||||||
@ -531,6 +531,7 @@ class Facture extends CommonInvoice
|
|||||||
else dol_print_error($resqlcontact);
|
else dol_print_error($resqlcontact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert lines of invoices into database
|
* Insert lines of invoices into database
|
||||||
*/
|
*/
|
||||||
@ -655,11 +656,20 @@ class Facture extends CommonInvoice
|
|||||||
$prod = new Product($this->db);
|
$prod = new Product($this->db);
|
||||||
$res=$prod->fetch($_facrec->lines[$i]->fk_product);
|
$res=$prod->fetch($_facrec->lines[$i]->fk_product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For line from template invoice, we use data from template invoice
|
||||||
|
/*
|
||||||
$tva_tx = get_default_tva($mysoc,$soc,$prod->id);
|
$tva_tx = get_default_tva($mysoc,$soc,$prod->id);
|
||||||
$tva_npr = get_default_npr($mysoc,$soc,$prod->id);
|
$tva_npr = get_default_npr($mysoc,$soc,$prod->id);
|
||||||
if (empty($tva_tx)) $tva_npr=0;
|
if (empty($tva_tx)) $tva_npr=0;
|
||||||
$localtax1_tx=get_localtax($tva_tx,1,$soc,$mysoc,$tva_npr);
|
$localtax1_tx=get_localtax($tva_tx,1,$soc,$mysoc,$tva_npr);
|
||||||
$localtax2_tx=get_localtax($tva_tx,2,$soc,$mysoc,$tva_npr);
|
$localtax2_tx=get_localtax($tva_tx,2,$soc,$mysoc,$tva_npr);
|
||||||
|
*/
|
||||||
|
$tva_tx = $_facrec->lines[$i]->tva_tx.($_facrec->lines[$i]->vat_src_code ? '('.$_facrec->lines[$i]->vat_src_code.')' : '');
|
||||||
|
$tva_npr = $_facrec->lines[$i]->info_bits;
|
||||||
|
if (empty($tva_tx)) $tva_npr=0;
|
||||||
|
$localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
|
||||||
|
$localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
|
||||||
|
|
||||||
$result_insert = $this->addline(
|
$result_insert = $this->addline(
|
||||||
$_facrec->lines[$i]->desc,
|
$_facrec->lines[$i]->desc,
|
||||||
@ -670,7 +680,11 @@ class Facture extends CommonInvoice
|
|||||||
$localtax2_tx,
|
$localtax2_tx,
|
||||||
$_facrec->lines[$i]->fk_product,
|
$_facrec->lines[$i]->fk_product,
|
||||||
$_facrec->lines[$i]->remise_percent,
|
$_facrec->lines[$i]->remise_percent,
|
||||||
'','',0,$tva_npr,'','HT',0,
|
'','',0,
|
||||||
|
$tva_npr,
|
||||||
|
'',
|
||||||
|
'HT',
|
||||||
|
0,
|
||||||
$_facrec->lines[$i]->product_type,
|
$_facrec->lines[$i]->product_type,
|
||||||
$_facrec->lines[$i]->rang,
|
$_facrec->lines[$i]->rang,
|
||||||
$_facrec->lines[$i]->special_code,
|
$_facrec->lines[$i]->special_code,
|
||||||
|
|||||||
@ -789,8 +789,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
// Define info_bits
|
// Define info_bits
|
||||||
$info_bits = 0;
|
$info_bits = 0;
|
||||||
if (preg_match('/\*/', $vat_rate))
|
if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
|
||||||
$info_bits |= 0x01;
|
|
||||||
|
|
||||||
// Define vat_rate
|
// Define vat_rate
|
||||||
$vat_rate = str_replace('*', '', $vat_rate);
|
$vat_rate = str_replace('*', '', $vat_rate);
|
||||||
@ -854,12 +853,13 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$price_min = $product->price_min;
|
$price_min = $product->price_min;
|
||||||
if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
|
if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
|
||||||
$price_min = $product->multiprices_min [$object->thirdparty->price_level];
|
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
|
||||||
|
|
||||||
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
||||||
|
|
||||||
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
|
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
|
||||||
if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
|
if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min)))
|
||||||
|
{
|
||||||
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
|
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
|
||||||
$error ++;
|
$error ++;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user