Ajout des modifications apportes par Laurent concernant les avoirs au niveau des commandes clients
This commit is contained in:
parent
c63eeb2cbd
commit
b88d907246
@ -1002,53 +1002,59 @@ class Commande extends CommonObject
|
||||
$result=$remise->fetch($idremise);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$comligne=new CommandeLigne($this->db);
|
||||
$comligne->fk_commande=$this->id;
|
||||
$comligne->fk_remise_except=$remise->id;
|
||||
$comligne->desc=$remise->description; // Description ligne
|
||||
$comligne->tva_tx=$remise->tva_tx;
|
||||
$comligne->subprice=-$remise->amount_ht;
|
||||
$comligne->price=-$remise->amount_ht;
|
||||
$comligne->fk_product=0; // Id produit prédéfini
|
||||
$comligne->qty=1;
|
||||
$comligne->remise=0;
|
||||
$comligne->remise_percent=0;
|
||||
$comligne->rang=-1;
|
||||
$comligne->info_bits=2;
|
||||
|
||||
$tabprice=calcul_price_total($comligne->qty, $comligne->subprice, 0,$comligne->tva_tx);
|
||||
$comligne->total_ht = $tabprice[0];
|
||||
$comligne->total_tva = $tabprice[1];
|
||||
$comligne->total_ttc = $tabprice[2];
|
||||
|
||||
$result=$comligne->insert();
|
||||
if ($result > 0)
|
||||
{
|
||||
$result=$this->update_price($this->id);
|
||||
if ($result > 0)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
{
|
||||
if ($remise->fk_facture) // Protection against multiple submission
|
||||
{
|
||||
$this->error=$langs->trans("ErrorDiscountAlreadyUsed");
|
||||
$this->db->rollback();
|
||||
return -5;
|
||||
}
|
||||
|
||||
$comligne=new CommandeLigne($this->db);
|
||||
$comligne->fk_commande=$this->id;
|
||||
$comligne->fk_remise_except=$remise->id;
|
||||
$comligne->desc=$remise->description; // Description ligne
|
||||
$comligne->tva_tx=$remise->tva_tx;
|
||||
$comligne->subprice=-$remise->amount_ht;
|
||||
$comligne->price=-$remise->amount_ht;
|
||||
$comligne->fk_product=0; // Id produit prédéfini
|
||||
$comligne->qty=1;
|
||||
$comligne->remise=0;
|
||||
$comligne->remise_percent=0;
|
||||
$comligne->rang=-1;
|
||||
$comligne->info_bits=2;
|
||||
|
||||
$comligne->total_ht = -$remise->amount_ht;
|
||||
$comligne->total_tva = -$remise->amount_tva;
|
||||
$comligne->total_ttc = -$remise->amount_ttc;
|
||||
|
||||
$result=$comligne->insert();
|
||||
if ($result > 0)
|
||||
{
|
||||
$result=$this->update_price($this->id);
|
||||
if ($result > 0)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
$this->error=$comligne->error;
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$comligne->error;
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1086,8 +1092,8 @@ class Commande extends CommonObject
|
||||
{
|
||||
$this->lignes = array();
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
||||
$sql.= ' l.remise_percent, l.subprice, l.coef, l.rang, l.info_bits,';
|
||||
$sql.= ' l.total_ht, l.total_ttc, l.total_tva,';
|
||||
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.coef, l.rang, l.info_bits,';
|
||||
$sql.= ' l.total_ht, l.total_ttc, l.total_tva,';
|
||||
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
|
||||
@ -1105,28 +1111,29 @@ class Commande extends CommonObject
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
$ligne = new CommandeLigne($this->db);
|
||||
$ligne->rowid = $objp->rowid;
|
||||
$ligne->id = $objp->rowid; // \deprecated
|
||||
$ligne->fk_commande = $objp->fk_commande;
|
||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||
$ligne->desc = $objp->description; // Description ligne
|
||||
$ligne->qty = $objp->qty;
|
||||
$ligne->tva_tx = $objp->tva_tx;
|
||||
$ligne->total_ht = $objp->total_ht;
|
||||
$ligne->total_ttc = $objp->total_ttc;
|
||||
$ligne->total_tva = $objp->total_tva;
|
||||
$ligne->subprice = $objp->subprice;
|
||||
$ligne->remise_percent = $objp->remise_percent;
|
||||
$ligne->price = $objp->price;
|
||||
$ligne->fk_product = $objp->fk_product;
|
||||
$ligne->coef = $objp->coef;
|
||||
$ligne->rang = $objp->rang;
|
||||
$ligne->info_bits = $objp->info_bits;
|
||||
$ligne->rowid = $objp->rowid;
|
||||
$ligne->id = $objp->rowid; // \deprecated
|
||||
$ligne->fk_commande = $objp->fk_commande;
|
||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||
$ligne->desc = $objp->description; // Description ligne
|
||||
$ligne->qty = $objp->qty;
|
||||
$ligne->tva_tx = $objp->tva_tx;
|
||||
$ligne->total_ht = $objp->total_ht;
|
||||
$ligne->total_ttc = $objp->total_ttc;
|
||||
$ligne->total_tva = $objp->total_tva;
|
||||
$ligne->subprice = $objp->subprice;
|
||||
$ligne->fk_remise_except = $objp->fk_remise_except;
|
||||
$ligne->remise_percent = $objp->remise_percent;
|
||||
$ligne->price = $objp->price;
|
||||
$ligne->fk_product = $objp->fk_product;
|
||||
$ligne->coef = $objp->coef;
|
||||
$ligne->rang = $objp->rang;
|
||||
$ligne->info_bits = $objp->info_bits;
|
||||
|
||||
$ligne->ref = $objp->product_ref;
|
||||
$ligne->libelle = $objp->label;
|
||||
$ligne->product_desc = $objp->product_desc; // Description produit
|
||||
$ligne->fk_product_type= $objp->fk_product_type; // Produit ou service
|
||||
$ligne->ref = $objp->product_ref;
|
||||
$ligne->libelle = $objp->label;
|
||||
$ligne->product_desc = $objp->product_desc; // Description produit
|
||||
$ligne->fk_product_type = $objp->fk_product_type; // Produit ou service
|
||||
|
||||
$this->lignes[$i] = $ligne;
|
||||
$i++;
|
||||
|
||||
@ -1262,7 +1262,7 @@ else
|
||||
/*
|
||||
* Lignes de commandes
|
||||
*/
|
||||
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.info_bits,';
|
||||
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,';
|
||||
$sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
|
||||
$sql.= ' p.description as product_desc';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
||||
@ -1326,7 +1326,20 @@ else
|
||||
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$commande->socid.'">';
|
||||
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
|
||||
print '</a>';
|
||||
if ($objp->description) print ' - '.nl2br($objp->description);
|
||||
if ($objp->description)
|
||||
{
|
||||
if ($objp->description == '(CREDIT_NOTE)')
|
||||
{
|
||||
$discount=new DiscountAbsolute($db);
|
||||
$discount->fetch($objp->fk_remise_except);
|
||||
print ' - '.$langs->trans("DiscountFromCreditNote",$discount->ref_facture_source);
|
||||
// \TODO Mettre ici lien sur ref avoir en ajoutant fonction getNomUrl sur classe DiscountAbsolute
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' - '.nl2br($objp->description);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1460,122 +1473,6 @@ else
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lignes de remise
|
||||
*/
|
||||
|
||||
// Réductions relatives (Remises-Ristournes-Rabbais)
|
||||
/* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
|
||||
et non globalement
|
||||
$var=!$var;
|
||||
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="action" value="setremisepercent">';
|
||||
print '<input type="hidden" name="id" value="'.$commande->id.'">';
|
||||
print '<tr class="liste_total"><td>';
|
||||
print $langs->trans('CustomerRelativeDiscount');
|
||||
if ($commande->brouillon) print ' <font style="font-weight: normal">('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')</font>';
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="right"><font style="font-weight: normal">';
|
||||
if ($_GET['action'] == 'editrelativediscount')
|
||||
{
|
||||
print '<input type="text" name="remise_percent" size="2" value="'.$commande->remise_percent.'">%';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $commande->remise_percent?$commande->remise_percent.'%':' ';
|
||||
}
|
||||
print '</font></td>';
|
||||
print '<td align="right"><font style="font-weight: normal">';
|
||||
if ($_GET['action'] != 'editrelativediscount') print $commande->remise_percent?'-'.price($commande->remise_percent*$total/100):$langs->trans("DiscountNone");
|
||||
else print ' ';
|
||||
print '</font></td>';
|
||||
if ($_GET['action'] != 'editrelativediscount')
|
||||
{
|
||||
if ($commande->brouillon && $user->rights->facture->creer)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editrelativediscount&id='.$commande->id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_percent)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=setremisepercent&rowid='.$objp->rowid.'">';
|
||||
print img_delete();
|
||||
print '</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
print '<td> </td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
*/
|
||||
|
||||
// Remise absolue
|
||||
/* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
|
||||
$var=!$var;
|
||||
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="action" value="setremiseabsolue">';
|
||||
print '<input type="hidden" name="id" value="'.$commande->id.'">';
|
||||
print '<tr class="liste_total"><td>';
|
||||
print $langs->trans('CustomerAbsoluteDiscount');
|
||||
if ($commande->brouillon) print ' <font style="font-weight: normal">('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')</font>';
|
||||
print '</td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td> </td>';
|
||||
print '<td align="right"><font style="font-weight: normal">';
|
||||
if ($_GET['action'] == 'editabsolutediscount')
|
||||
{
|
||||
print '-<input type="text" name="remise_absolue" size="2" value="'.$commande->remise_absolue.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $commande->remise_absolue?'-'.price($commande->remise_absolue):$langs->trans("DiscountNone");
|
||||
}
|
||||
print '</font></td>';
|
||||
if ($_GET['action'] != 'editabsolutediscount')
|
||||
{
|
||||
if ($commande->brouillon && $user->rights->facture->creer)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editabsolutediscount&id='.$commande->id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
if ($commande->brouillon && $user->rights->facture->creer && $commande->remise_absolue)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=setremiseabsolue&rowid='.$objp->rowid.'">';
|
||||
print img_delete();
|
||||
print '</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
print '<td> </td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ajouter une ligne
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user