Ajout des modifications apportées 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);
|
$result=$remise->fetch($idremise);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$comligne=new CommandeLigne($this->db);
|
if ($remise->fk_facture) // Protection against multiple submission
|
||||||
$comligne->fk_commande=$this->id;
|
{
|
||||||
$comligne->fk_remise_except=$remise->id;
|
$this->error=$langs->trans("ErrorDiscountAlreadyUsed");
|
||||||
$comligne->desc=$remise->description; // Description ligne
|
$this->db->rollback();
|
||||||
$comligne->tva_tx=$remise->tva_tx;
|
return -5;
|
||||||
$comligne->subprice=-$remise->amount_ht;
|
}
|
||||||
$comligne->price=-$remise->amount_ht;
|
|
||||||
$comligne->fk_product=0; // Id produit prédéfini
|
$comligne=new CommandeLigne($this->db);
|
||||||
$comligne->qty=1;
|
$comligne->fk_commande=$this->id;
|
||||||
$comligne->remise=0;
|
$comligne->fk_remise_except=$remise->id;
|
||||||
$comligne->remise_percent=0;
|
$comligne->desc=$remise->description; // Description ligne
|
||||||
$comligne->rang=-1;
|
$comligne->tva_tx=$remise->tva_tx;
|
||||||
$comligne->info_bits=2;
|
$comligne->subprice=-$remise->amount_ht;
|
||||||
|
$comligne->price=-$remise->amount_ht;
|
||||||
$tabprice=calcul_price_total($comligne->qty, $comligne->subprice, 0,$comligne->tva_tx);
|
$comligne->fk_product=0; // Id produit prédéfini
|
||||||
$comligne->total_ht = $tabprice[0];
|
$comligne->qty=1;
|
||||||
$comligne->total_tva = $tabprice[1];
|
$comligne->remise=0;
|
||||||
$comligne->total_ttc = $tabprice[2];
|
$comligne->remise_percent=0;
|
||||||
|
$comligne->rang=-1;
|
||||||
$result=$comligne->insert();
|
$comligne->info_bits=2;
|
||||||
if ($result > 0)
|
|
||||||
{
|
$comligne->total_ht = -$remise->amount_ht;
|
||||||
$result=$this->update_price($this->id);
|
$comligne->total_tva = -$remise->amount_tva;
|
||||||
if ($result > 0)
|
$comligne->total_ttc = -$remise->amount_ttc;
|
||||||
{
|
|
||||||
$this->db->commit();
|
$result=$comligne->insert();
|
||||||
return 1;
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$result=$this->update_price($this->id);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->error=$comligne->error;
|
||||||
return -1;
|
$this->db->rollback();
|
||||||
}
|
return -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$comligne->error;
|
|
||||||
$this->db->rollback();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1086,8 +1092,8 @@ class Commande extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->lignes = array();
|
$this->lignes = array();
|
||||||
$sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
$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.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.= ' 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.= ' 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.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
|
$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);
|
$objp = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$ligne = new CommandeLigne($this->db);
|
$ligne = new CommandeLigne($this->db);
|
||||||
$ligne->rowid = $objp->rowid;
|
$ligne->rowid = $objp->rowid;
|
||||||
$ligne->id = $objp->rowid; // \deprecated
|
$ligne->id = $objp->rowid; // \deprecated
|
||||||
$ligne->fk_commande = $objp->fk_commande;
|
$ligne->fk_commande = $objp->fk_commande;
|
||||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||||
$ligne->desc = $objp->description; // Description ligne
|
$ligne->desc = $objp->description; // Description ligne
|
||||||
$ligne->qty = $objp->qty;
|
$ligne->qty = $objp->qty;
|
||||||
$ligne->tva_tx = $objp->tva_tx;
|
$ligne->tva_tx = $objp->tva_tx;
|
||||||
$ligne->total_ht = $objp->total_ht;
|
$ligne->total_ht = $objp->total_ht;
|
||||||
$ligne->total_ttc = $objp->total_ttc;
|
$ligne->total_ttc = $objp->total_ttc;
|
||||||
$ligne->total_tva = $objp->total_tva;
|
$ligne->total_tva = $objp->total_tva;
|
||||||
$ligne->subprice = $objp->subprice;
|
$ligne->subprice = $objp->subprice;
|
||||||
$ligne->remise_percent = $objp->remise_percent;
|
$ligne->fk_remise_except = $objp->fk_remise_except;
|
||||||
$ligne->price = $objp->price;
|
$ligne->remise_percent = $objp->remise_percent;
|
||||||
$ligne->fk_product = $objp->fk_product;
|
$ligne->price = $objp->price;
|
||||||
$ligne->coef = $objp->coef;
|
$ligne->fk_product = $objp->fk_product;
|
||||||
$ligne->rang = $objp->rang;
|
$ligne->coef = $objp->coef;
|
||||||
$ligne->info_bits = $objp->info_bits;
|
$ligne->rang = $objp->rang;
|
||||||
|
$ligne->info_bits = $objp->info_bits;
|
||||||
|
|
||||||
$ligne->ref = $objp->product_ref;
|
$ligne->ref = $objp->product_ref;
|
||||||
$ligne->libelle = $objp->label;
|
$ligne->libelle = $objp->label;
|
||||||
$ligne->product_desc = $objp->product_desc; // Description produit
|
$ligne->product_desc = $objp->product_desc; // Description produit
|
||||||
$ligne->fk_product_type= $objp->fk_product_type; // Produit ou service
|
$ligne->fk_product_type = $objp->fk_product_type; // Produit ou service
|
||||||
|
|
||||||
$this->lignes[$i] = $ligne;
|
$this->lignes[$i] = $ligne;
|
||||||
$i++;
|
$i++;
|
||||||
|
|||||||
@ -1262,7 +1262,7 @@ else
|
|||||||
/*
|
/*
|
||||||
* Lignes de commandes
|
* 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.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
|
||||||
$sql.= ' p.description as product_desc';
|
$sql.= ' p.description as product_desc';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
$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 '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$commande->socid.'">';
|
||||||
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
|
print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount");
|
||||||
print '</a>';
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -1460,122 +1473,6 @@ else
|
|||||||
dolibarr_print_error($db);
|
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
|
* Ajouter une ligne
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user