Rewrite code for supplier order and invoice to use shared code of

customer supplier and invoice.
Work on extrafield for supplier order and invoice.
This commit is contained in:
Laurent Destailleur 2015-02-28 18:10:31 +01:00
parent 8e26c71fa7
commit 4d226885cb
7 changed files with 138 additions and 80 deletions

View File

@ -2573,39 +2573,38 @@ abstract class CommonObject
*/
function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0, $permtoedit=0)
{
global $conf, $hookmanager, $inputalsopricewithtax, $usermargins, $langs, $user;
global $conf, $hookmanager, $inputalsopricewithtax, $usemargins, $langs, $user;
# Define usemargins
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
print '<tr class="liste_titre nodrag nodrop">';
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td align="center" width="5">&nbsp;</td>';
// Description
print '<td><label for="">'.$langs->trans('Description').'</label></td>';
print '<td>'.$langs->trans('Description').'</td>';
// VAT
print '<td align="right" width="50"><label for="tva_tx">'.$langs->trans('VAT').'</label></td>';
print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
// Price HT
print '<td align="right" width="80"><label for="price_ht">'.$langs->trans('PriceUHT').'</label></td>';
print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
if ($inputalsopricewithtax) print '<td align="right" width="80">&nbsp;</td>';
if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
// Qty
print '<td align="right" width="50"><label for="qty">'.$langs->trans('Qty').'</label></td>';
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
// Reduction short
print '<td align="right" width="50"><label for="remise_percent">'.$langs->trans('ReductionShort').'</label></td>';
print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
if ($this->situation_cycle_ref) {
print '<td align="right" width="50"><label for="progress">' . $langs->trans('Progress') . '</label></td>';
print '<td align="right" width="50">' . $langs->trans('Progress') . '</td>';
}
if ($usermargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
{
if ($conf->global->MARGIN_TYPE == "1")
print '<td align="right" class="margininfos" width="80">'.$langs->trans('BuyingPrice').'</td>';

View File

@ -43,7 +43,7 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
// Define colspan for button Add
$colspan = 3; // Col total ht + col edit + col delete
if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
if (in_array($object->element,array('propal','facture','invoice','commande','order'))) $colspan++; // With this, there is a column move button
if (in_array($object->element,array('propal','facture','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
?>
<!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
@ -109,20 +109,18 @@ $coldisplay=-1; // We remove first td
}
$coldisplay++;
print '<td align="right"><input type="text" class="flat" size="8" id="price_ht" name="price_ht" value="' . price($line->subprice,0,'',0) . '" ';
if ($this->situation_counter > 1) {
print 'readonly="readonly" ';
}
print '<td align="right"><input type="text" class="flat" size="8" id="price_ht" name="price_ht" value="' . (isset($line->pu_ht)?price($line->pu_ht,0,'',0):price($line->subprice,0,'',0)) . '"';
if ($this->situation_counter > 1) print ' readonly="readonly"';
print '></td>';
if ($inputalsopricewithtax) {
if ($inputalsopricewithtax)
{
$coldisplay++;
print '<td align="right"><input type="text" class="flat" size="8" id="price_ttc" name="price_ttc" value="' . price($pu_ttc,0,'',0) . '"';
if ($this->situation_counter > 1) {
print 'readonly="readonly" ';
}
print '<td align="right"><input type="text" class="flat" size="8" id="price_ttc" name="price_ttc" value="'.(isset($line->pu_ttc)?price($line->pu_ttc,0,'',0):'').'"';
if ($this->situation_counter > 1) print ' readonly="readonly"';
print '></td>';
} ?>
}
?>
<td align="right"><?php $coldisplay++; ?>
<?php if (($line->info_bits & 2) != 2) {
@ -130,11 +128,9 @@ $coldisplay=-1; // We remove first td
// for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
// must also not be output for most entities (proposal, intervention, ...)
//if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
print '<input size="3" type="text" class="flat" name="qty" id="qty" value="' . $line->qty . '" ';
if ($this->situation_counter > 1) {
print 'readonly="readonly" ';
}
print '/>';
print '<input size="3" type="text" class="flat" name="qty" id="qty" value="' . $line->qty . '"';
if ($this->situation_counter > 1) print ' readonly="readonly"';
print '>';
} else { ?>
&nbsp;
<?php } ?>
@ -142,11 +138,9 @@ $coldisplay=-1; // We remove first td
<td align="right" nowrap><?php $coldisplay++; ?>
<?php if (($line->info_bits & 2) != 2) {
print '<input size="1" type="text" class="flat" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '" ';
if ($this->situation_counter > 1) {
print 'readonly="readonly" ';
}
print '/>%';
print '<input size="1" type="text" class="flat" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '"';
if ($this->situation_counter > 1) print ' readonly="readonly"';
print '>%';
} else { ?>
&nbsp;
<?php } ?>
@ -189,7 +183,8 @@ $coldisplay=-1; // We remove first td
$coldisplay++;
}
}
} ?>
}
?>
<!-- colspan=4 for this td because it replace total_ht+3 td for buttons -->
<td align="center" colspan="<?php echo $colspan; ?>" valign="middle"><?php $coldisplay+=4; ?>

View File

@ -122,10 +122,10 @@ if (empty($usemargins)) $usemargins=0;
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo vatrate($line->tva_tx,'%',$line->info_bits); ?></td>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo price($line->subprice); ?></td>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo (isset($line->pu_ht)?price($line->pu_ht):price($line->subprice)); ?></td>
<?php if ($inputalsopricewithtax) { ?>
<td align="right" class="nowrap"><?php $coldisplay++; ?>&nbsp;</td>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo (isset($line->pu_ttc)?price($line->pu_ttc):price($line->subprice)); ?></td>
<?php } ?>
<td align="right" class="nowrap"><?php $coldisplay++; ?>
@ -139,7 +139,11 @@ if (empty($usemargins)) $usemargins=0;
</td>
<?php if (!empty($line->remise_percent) && $line->special_code != 3) { ?>
<td align="right"><?php $coldisplay++; ?><?php echo dol_print_reduction($line->remise_percent,$langs); ?></td>
<td align="right"><?php
$coldisplay++;
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
echo dol_print_reduction($line->remise_percent,$langs);
?></td>
<?php } else { ?>
<td><?php $coldisplay++; ?>&nbsp;</td>
<?php }
@ -149,7 +153,7 @@ if (empty($usemargins)) $usemargins=0;
print '<td align="right" nowrap="nowrap">' . $line->situation_percent . '%</td>';
}
if ($usermargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
{
$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
?>

View File

@ -1873,8 +1873,19 @@ class CommandeFournisseur extends CommonOrder
if ($result > 0)
{
$this->rowid = $rowid;
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$tmpline = new CommandeFournisseurLigne($this->db);
$tmpline->id=$this->rowid;
$tmpline->array_options = $array_options;
$result=$tmpline->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
if (! $notrigger)
if (! $error && ! $notrigger)
{
global $conf, $langs, $user;
// Call trigger
@ -1888,14 +1899,25 @@ class CommandeFournisseur extends CommonOrder
}
// Mise a jour info denormalisees au niveau facture
$this->update_price('','auto');
if (! $error)
{
$this->update_price('','auto');
}
$this->db->commit();
return $result;
if (! $error)
{
$this->db->commit();
return $result;
}
else
{
$this->db->rollback();
return -1;
}
}
else
{
$this->error=$this->db->error();
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
@ -2163,17 +2185,22 @@ class CommandeFournisseur extends CommonOrder
*/
function getMaxDeliveryTimeDay($langs)
{
if (empty($this->lines)) return $langs->trans('Undefined');
if (empty($this->lines)) return '';
$obj = new ProductFournisseur($this->db);
$nb = 0;
foreach ($this->lines as $line) {
$obj = new ProductFournisseur($this->db);
$idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
if ($idp) {
$obj->fetch($idp);
if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
foreach ($this->lines as $line)
{
if ($line->fk_product > 0)
{
$idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
if ($idp)
{
$obj->fetch($idp);
if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
}
}
}
if ($nb === 0) return $langs->trans('Undefined');

View File

@ -1323,9 +1323,16 @@ class FactureFournisseur extends CommonInvoice
// Update total price into invoice record
$result=$this->update_price('','auto');
$this->db->commit();
return $result;
if (! $error)
{
$this->db->commit();
return $result;
}
else
{
$this->db->rollback();
return -1;
}
}
else
{
@ -1847,6 +1854,9 @@ class FactureFournisseurLigne extends CommonInvoice
var $db;
var $error;
var $pu_ht;
var $pu_ttc;
public $element='facture_fourn_det';
public $table_element='facture_fourn_det';

View File

@ -347,16 +347,16 @@ if (empty($reshook))
$localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
$localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
if (!empty($_POST['price_ht']))
if (GETPOST('price_ht')!=='')
{
$price_base_type = 'HT';
$ht = price2num($_POST['price_ht']);
$ht = price2num(GETPOST('price_ht'));
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end, $array_options);
}
else
{
$ttc = price2num($_POST['price_ttc']);
$ht = $ttc / (1 + ($tauxtva / 100));
$ttc = price2num(GETPOST('price_ttc'));
$ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options);
}
@ -426,18 +426,34 @@ if (empty($reshook))
*/
if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
{
if ($_POST["elrowid"])
$tva_tx = GETPOST('tva_tx');
if (GETPOST('price_ht') != '')
{
$price_base_type = 'HT';
$ht = price2num(GETPOST('price_ht'));
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end);
}
else
{
$ttc = price2num(GETPOST('price_ttc'));
$ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end);
}
if ($lineid)
{
$line = new CommandeFournisseurLigne($db);
$res = $line->fetch($_POST["elrowid"]);
$res = $line->fetch($lineid);
if (!$res) dol_print_error($db);
}
$date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
$date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
$localtax1_tx=get_localtax($_POST['tva_tx'],1,$mysoc,$object->thirdparty);
$localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty);
$localtax1_tx=get_localtax($tva_tx,1,$mysoc,$object->thirdparty);
$localtax2_tx=get_localtax($tva_tx,2,$mysoc,$object->thirdparty);
// Extrafields Lines
$extrafieldsline = new ExtraFields($db);
@ -451,21 +467,21 @@ if (empty($reshook))
}
$result = $object->updateline(
$_POST['elrowid'],
$_POST['eldesc'],
$_POST['pu'],
$lineid,
$_POST['product_desc'],
$ht,
$_POST['qty'],
$_POST['remise_percent'],
$_POST['tva_tx'],
$tva_tx,
$localtax1_tx,
$localtax2_tx,
'HT',
$price_base_type,
0,
isset($_POST["type"])?$_POST["type"]:$line->product_type,
false,
$date_start,
$date_end,
$array_option
$array_options
);
unset($_POST['qty']);
unset($_POST['type']);
@ -1730,7 +1746,7 @@ elseif (! empty($object->id))
$forceall=1; $senderissupplier=1; $dateSelector=0;
// Show object lines
$inputalsopricewithtax=1;
$inputalsopricewithtax=0;
if (! empty($object->lines))
$ret = $object->printObjectLines($action, $soc, $mysoc, $lineid, 1, $user->rights->fournisseur->commande->creer);

View File

@ -438,7 +438,10 @@ if (empty($reshook))
0,
$lines[$i]->info_bits,
'HT',
$product_type
$product_type,
$lines[$i]->rang,
1,
$lines[$i]->array_options
);
if ($result < 0)
@ -492,7 +495,7 @@ if (empty($reshook))
$product=new Product($db);
$product->fetch($_POST['idprod'.$i]);
$ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
$ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base, $_POST['rang'.$i], 1);
if ($ret < 0) $error++;
}
}
@ -535,16 +538,20 @@ if (empty($reshook))
$object->fetch($id);
$object->fetch_thirdparty();
if ($_POST['puht'])
{
$pu=$_POST['puht'];
$price_base_type='HT';
}
if ($_POST['puttc'])
{
$pu=$_POST['puttc'];
$price_base_type='TTC';
}
$tva_tx = GETPOST('tva_tx');
if (GETPOST('price_ht') != '')
{
$up = price2num(GETPOST('price_ht'));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end);
}
else
{
$up = price2num(GETPOST('price_ttc'));
$price_base_type = 'TTC';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end);
}
if (GETPOST('idprod'))
{
@ -579,7 +586,7 @@ if (empty($reshook))
}
}
$result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options);
$result=$object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options);
if ($result >= 0)
{
unset($_POST['label']);