Fix vat npr for template invoices

This commit is contained in:
Laurent Destailleur 2018-01-17 19:45:23 +01:00
parent 4034122169
commit 57f664c0c1
4 changed files with 126 additions and 110 deletions

View File

@ -840,8 +840,8 @@ if (empty($reshook))
$object->date = $dateinvoice;
$object->date_pointoftax = $date_pointoftax;
$object->note_public = trim($_POST['note_public']);
$object->note = trim($_POST['note']);
$object->note_public = trim(GETPOST('note_public','none'));
// We do not copy the private note
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
@ -854,7 +854,7 @@ if (empty($reshook))
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// Proprietes particulieres a facture de remplacement
$object->fk_facture_source = $_POST['fac_replacement'];
@ -892,8 +892,8 @@ if (empty($reshook))
$object->number = $_POST['facnumber'];
$object->date = $dateinvoice;
$object->date_pointoftax = $date_pointoftax;
$object->note_public = trim($_POST['note_public']);
$object->note = trim($_POST['note']);
$object->note_public = trim(GETPOST('note_public','none'));
// We do not copy the private note
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
@ -906,7 +906,7 @@ if (empty($reshook))
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// Proprietes particulieres a facture avoir
$object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
@ -989,17 +989,17 @@ if (empty($reshook))
if (! $error)
{
$object->socid = GETPOST('socid','int');
$object->type = $_POST['type'];
$object->number = $_POST['facnumber'];
$object->socid = GETPOST('socid','int');
$object->type = $_POST['type'];
$object->number = $_POST['facnumber'];
$object->date = $dateinvoice;
$object->date_pointoftax = $date_pointoftax;
$object->note_public = trim($_POST['note_public']);
$object->note_private = trim($_POST['note_private']);
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
$object->fk_project = $_POST['projectid'];
$object->note_public = trim(GETPOST('note_public','none'));
$object->note_private = trim(GETPOST('note_private','none'));
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
$object->fk_project = $_POST['projectid'];
$object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
$object->mode_reglement_id = $_POST['mode_reglement_id'];
$object->fk_account = GETPOST('fk_account', 'int');
@ -1009,12 +1009,12 @@ if (empty($reshook))
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// 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->date = $dateinvoice;
$object->date_pointoftax = $date_pointoftax;
$object->note_public = trim($_POST['note_public']);
$object->note_private = trim($_POST['note_private']);
$object->note_public = trim(GETPOST('note_public','none'));
$object->note_private = trim(GETPOST('note_private','none'));
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
@ -1059,7 +1059,7 @@ if (empty($reshook))
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
if (GETPOST('type') == Facture::TYPE_SITUATION)
{
@ -1905,8 +1905,7 @@ if (empty($reshook))
// Define info_bits
$info_bits = 0;
if (preg_match('/\*/', $vat_rate))
$info_bits |= 0x01;
if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
// Define vat_rate
$vat_rate = str_replace('*', '', $vat_rate);

View File

@ -202,7 +202,7 @@ class FactureRec extends CommonInvoice
$facsrc->lines[$i]->fk_product,
$facsrc->lines[$i]->remise_percent,
'HT',
0,
$facsrc->lines[$i]->info_bits,
'',
0,
$facsrc->lines[$i]->product_type,
@ -596,7 +596,7 @@ class FactureRec extends CommonInvoice
* @param int $fk_product Id du produit/service predefini
* @param double $remise_percent Pourcentage de remise de la ligne
* @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 double $pu_ttc Prix unitaire TTC (> 0 even for credit note)
* @param int $type Type of line (0=product, 1=service)
@ -635,7 +635,6 @@ class FactureRec extends CommonInvoice
$remise_percent=price2num($remise_percent);
if (empty($remise_percent)) $remise_percent=0;
$qty=price2num($qty);
if (! $info_bits) $info_bits=0;
$pu_ht = price2num($pu_ht);
$pu_ttc = price2num($pu_ttc);
$txtva = price2num($txtva);
@ -644,6 +643,7 @@ class FactureRec extends CommonInvoice
if (empty($txtva)) $txtva=0;
if (empty($txlocaltax1)) $txlocaltax1=0;
if (empty($txlocaltax2)) $txlocaltax2=0;
if (empty($info_bits)) $info_bits=0;
if ($price_base_type=='HT')
{
@ -703,6 +703,7 @@ class FactureRec extends CommonInvoice
$sql.= ", total_localtax1";
$sql.= ", total_localtax2";
$sql.= ", total_ttc";
$sql.= ", info_bits";
$sql.= ", rang";
$sql.= ", special_code";
$sql.= ", fk_unit";
@ -729,6 +730,7 @@ class FactureRec extends CommonInvoice
$sql.= ", ".price2num($total_localtax1);
$sql.= ", ".price2num($total_localtax2);
$sql.= ", ".price2num($total_ttc);
$sql.= ", ".$info_bits;
$sql.= ", ".$rang;
$sql.= ", ".$special_code;
$sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");
@ -811,7 +813,7 @@ class FactureRec extends CommonInvoice
// Clean parameters
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $info_bits) $info_bits=0;
if (empty($info_bits)) $info_bits=0;
$pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc);
$txtva=price2num($txtva);
@ -884,6 +886,7 @@ class FactureRec extends CommonInvoice
$sql.= ", total_localtax1='".price2num($total_localtax1)."'";
$sql.= ", total_localtax2='".price2num($total_localtax2)."'";
$sql.= ", total_ttc='".price2num($total_ttc)."'";
$sql.= ", info_bits=".$info_bits;
$sql.= ", rang=".$rang;
$sql.= ", special_code=".$special_code;
$sql.= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null");

View File

@ -531,6 +531,7 @@ class Facture extends CommonInvoice
else dol_print_error($resqlcontact);
}
/*
* Insert lines of invoices into database
*/
@ -655,11 +656,20 @@ class Facture extends CommonInvoice
$prod = new Product($this->db);
$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_npr = get_default_npr($mysoc,$soc,$prod->id);
if (empty($tva_tx)) $tva_npr=0;
$localtax1_tx=get_localtax($tva_tx,1,$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(
$_facrec->lines[$i]->desc,
@ -670,7 +680,11 @@ class Facture extends CommonInvoice
$localtax2_tx,
$_facrec->lines[$i]->fk_product,
$_facrec->lines[$i]->remise_percent,
'','',0,$tva_npr,'','HT',0,
'','',0,
$tva_npr,
'',
'HT',
0,
$_facrec->lines[$i]->product_type,
$_facrec->lines[$i]->rang,
$_facrec->lines[$i]->special_code,

View File

@ -789,64 +789,63 @@ if (empty($reshook))
// Define info_bits
$info_bits = 0;
if (preg_match('/\*/', $vat_rate))
$info_bits |= 0x01;
if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01;
// Define vat_rate
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
// Define vat_rate
$vat_rate = str_replace('*', '', $vat_rate);
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
// Add buying price
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
// Add buying price
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
$objectline = new FactureLigneRec($db);
if ($objectline->fetch(GETPOST('lineid')))
$objectline = new FactureLigneRec($db);
if ($objectline->fetch(GETPOST('lineid')))
{
$objectline->array_options=$array_options;
$result=$objectline->insertExtraFields();
if ($result < 0)
{
$objectline->array_options=$array_options;
$result=$objectline->insertExtraFields();
if ($result < 0)
{
setEventMessages($langs->trans('Error').$result, null, 'errors');
}
setEventMessages($langs->trans('Error').$result, null, 'errors');
}
}
// Unset extrafield
if (is_array($extralabelsline))
// Unset extrafield
if (is_array($extralabelsline))
{
// Get extra fields
foreach ($extralabelsline as $key => $value)
{
// Get extra fields
foreach ($extralabelsline as $key => $value)
{
unset($_POST["options_" . $key]);
}
unset($_POST["options_" . $key]);
}
}
// Define special_code for special lines
$special_code=GETPOST('special_code');
if (! GETPOST('qty')) $special_code=3;
// Define special_code for special lines
$special_code=GETPOST('special_code');
if (! GETPOST('qty')) $special_code=3;
/*$line = new FactureLigne($db);
$line->fetch(GETPOST('lineid'));
$percent = $line->get_prev_progress($object->id);
/*$line = new FactureLigne($db);
$line->fetch(GETPOST('lineid'));
$percent = $line->get_prev_progress($object->id);
if (GETPOST('progress') < $percent)
{
if (GETPOST('progress') < $percent)
{
$mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
setEventMessages($mesg, null, 'warnings');
$error++;
$result = -1;
}*/
}*/
// Check minimum price
$productid = GETPOST('productid', 'int');
if (! empty($productid))
{
// Check minimum price
$productid = GETPOST('productid', 'int');
if (! empty($productid))
{
$product = new Product($db);
$product->fetch($productid);
@ -854,18 +853,19 @@ if (empty($reshook))
$price_min = $product->price_min;
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)
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');
$error ++;
}
} else {
$type = GETPOST('type');
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
// 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)))
{
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
$error ++;
}
} else {
$type = GETPOST('type');
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
// Check parameters
if (GETPOST('type') < 0) {
@ -873,39 +873,39 @@ if (empty($reshook))
$error ++;
}
}
if ($qty < 0) {
$langs->load("errors");
setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
$error ++;
}
if ($qty < 0) {
$langs->load("errors");
setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
$error ++;
}
// Update line
if (! $error)
// Update line
if (! $error)
{
$result = $object->updateline(
GETPOST('lineid'),
$description,
$pu_ht,
$qty,
$vat_rate,
$localtax1_rate,
$localtax1_rate,
GETPOST('productid'),
GETPOST('remise_percent'),
'HT',
$info_bits,
0,
0,
$type,
0,
$special_code,
$label,
GETPOST('units'),
$pu_ht_devise
);
if ($result >= 0)
{
$result = $object->updateline(
GETPOST('lineid'),
$description,
$pu_ht,
$qty,
$vat_rate,
$localtax1_rate,
$localtax1_rate,
GETPOST('productid'),
GETPOST('remise_percent'),
'HT',
$info_bits,
0,
0,
$type,
0,
$special_code,
$label,
GETPOST('units'),
$pu_ht_devise
);
if ($result >= 0)
{
/*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
// Define output language
$outputlangs = $langs;