Skip to content

Commit

Permalink
Fix vat npr for template invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 17, 2018
1 parent 4034122 commit 57f664c
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 110 deletions.
45 changes: 22 additions & 23 deletions htdocs/compta/facture/card.php
Expand Up @@ -840,8 +840,8 @@

$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'];
Expand All @@ -854,7 +854,7 @@
$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'];
Expand Down Expand Up @@ -892,8 +892,8 @@
$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'];
Expand All @@ -906,7 +906,7 @@
$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 : '';
Expand Down Expand Up @@ -989,17 +989,17 @@

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');
Expand All @@ -1009,12 +1009,12 @@
$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
}
}

Expand Down Expand Up @@ -1044,8 +1044,8 @@
$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'];
Expand All @@ -1059,7 +1059,7 @@
$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)
{
Expand Down Expand Up @@ -1905,8 +1905,7 @@

// 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);
Expand Down
11 changes: 7 additions & 4 deletions htdocs/compta/facture/class/facture-rec.class.php
Expand Up @@ -202,7 +202,7 @@ function create($user, $facid)
$facsrc->lines[$i]->fk_product,
$facsrc->lines[$i]->remise_percent,
'HT',
0,
$facsrc->lines[$i]->info_bits,
'',
0,
$facsrc->lines[$i]->product_type,
Expand Down Expand Up @@ -596,7 +596,7 @@ function delete(User $user, $notrigger=0, $idwarehouse=-1)
* @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)
Expand Down Expand Up @@ -635,7 +635,6 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
$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);
Expand All @@ -644,6 +643,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
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')
{
Expand Down Expand Up @@ -703,6 +703,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
$sql.= ", total_localtax1";
$sql.= ", total_localtax2";
$sql.= ", total_ttc";
$sql.= ", info_bits";
$sql.= ", rang";
$sql.= ", special_code";
$sql.= ", fk_unit";
Expand All @@ -729,6 +730,7 @@ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $f
$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");
Expand Down Expand Up @@ -811,7 +813,7 @@ function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txloca
// 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);
Expand Down Expand Up @@ -884,6 +886,7 @@ function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txloca
$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");
Expand Down
16 changes: 15 additions & 1 deletion htdocs/compta/facture/class/facture.class.php
Expand Up @@ -531,6 +531,7 @@ function create($user,$notrigger=0,$forceduedate=0)
else dol_print_error($resqlcontact);
}


/*
* Insert lines of invoices into database
*/
Expand Down Expand Up @@ -655,11 +656,20 @@ function create($user,$notrigger=0,$forceduedate=0)
$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,
Expand All @@ -670,7 +680,11 @@ function create($user,$notrigger=0,$forceduedate=0)
$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,
Expand Down

0 comments on commit 57f664c

Please sign in to comment.