Simplification gestion des lignes factures/commandes/propales
This commit is contained in:
parent
8d7bb266ef
commit
45af9432bf
@ -488,39 +488,39 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
|
|||||||
if ($_POST['qty'] && (($_POST['np_price']!='' && $_POST['np_desc']) || $_POST['idprod']))
|
if ($_POST['qty'] && (($_POST['np_price']!='' && $_POST['np_desc']) || $_POST['idprod']))
|
||||||
{
|
{
|
||||||
$propal = new Propal($db);
|
$propal = new Propal($db);
|
||||||
$ret=$propal->fetch($_POST['propalid']);
|
$ret=$propal->fetch($_POST['propalid']);
|
||||||
if ($ret < 0)
|
if ($ret < 0)
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db,$propal->error);
|
dolibarr_print_error($db,$propal->error);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
$ret=$propal->fetch_client();
|
$ret=$propal->fetch_client();
|
||||||
|
|
||||||
$price_base_type = 'HT';
|
$price_base_type = 'HT';
|
||||||
|
|
||||||
// Ecrase $pu par celui du produit
|
// Ecrase $pu par celui du produit
|
||||||
// Ecrase $desc par celui du produit
|
// Ecrase $desc par celui du produit
|
||||||
// Ecrase $txtva par celui du produit
|
// Ecrase $txtva par celui du produit
|
||||||
if ($_POST['idprod'])
|
if ($_POST['idprod'])
|
||||||
{
|
{
|
||||||
$prod = new Product($db, $_POST['idprod']);
|
$prod = new Product($db, $_POST['idprod']);
|
||||||
$prod->fetch($_POST['idprod']);
|
$prod->fetch($_POST['idprod']);
|
||||||
|
|
||||||
$tva_tx = get_default_tva($mysoc,$propal->client,$prod->tva_tx);
|
$tva_tx = get_default_tva($mysoc,$propal->client,$prod->tva_tx);
|
||||||
|
|
||||||
// On defini prix unitaire
|
// On defini prix unitaire
|
||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$pu_ht = $prod->multiprices[$propal->client->price_level];
|
$pu_ht = $prod->multiprices[$propal->client->price_level];
|
||||||
$pu_ttc = $prod->multiprices_ttc[$propal->client->price_level];
|
$pu_ttc = $prod->multiprices_ttc[$propal->client->price_level];
|
||||||
$price_base_type = $prod->multiprices_base_type[$propal->client->price_level];
|
$price_base_type = $prod->multiprices_base_type[$propal->client->price_level];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu_ht = $prod->price;
|
$pu_ht = $prod->price;
|
||||||
$pu_ttc = $prod->price_ttc;
|
$pu_ttc = $prod->price_ttc;
|
||||||
$price_base_type = $prod->price_base_type;
|
$price_base_type = $prod->price_base_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
||||||
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
||||||
@ -536,18 +536,18 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$desc = $prod->description;
|
$desc = $prod->description;
|
||||||
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
|
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
|
||||||
$desc.= $_POST['np_desc'];
|
$desc.= $_POST['np_desc'];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu_ht=$_POST['np_price'];
|
$pu_ht=$_POST['np_price'];
|
||||||
$tva_tx=$_POST['np_tva_tx'];
|
$tva_tx=$_POST['np_tva_tx'];
|
||||||
$desc=$_POST['np_desc'];
|
$desc=$_POST['np_desc'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$propal->addline(
|
$result=$propal->addline(
|
||||||
$_POST['propalid'],
|
$_POST['propalid'],
|
||||||
$desc,
|
$desc,
|
||||||
$pu_ht,
|
$pu_ht,
|
||||||
@ -557,14 +557,22 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
|
|||||||
$_POST['remise_percent'],
|
$_POST['remise_percent'],
|
||||||
$price_base_type,
|
$price_base_type,
|
||||||
$pu_ttc
|
$pu_ttc
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($_REQUEST['lang_id'])
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
|
if ($_REQUEST['lang_id'])
|
||||||
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
{
|
||||||
|
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
|
||||||
|
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||||
|
}
|
||||||
|
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
|
||||||
}
|
}
|
||||||
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$propal->error.'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -327,13 +327,13 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$pu_ht = $prod->multiprices[$commande->client->price_level];
|
$pu_ht = $prod->multiprices[$commande->client->price_level];
|
||||||
$pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];
|
$pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];
|
||||||
$price_base_type = $prod->multiprices_base_type[$commande->client->price_level];
|
$price_base_type = $prod->multiprices_base_type[$commande->client->price_level];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu_ht = $prod->price;
|
$pu_ht = $prod->price;
|
||||||
$pu_ttc = $prod->price_ttc;
|
$pu_ttc = $prod->price_ttc;
|
||||||
$price_base_type = $prod->price_base_type;
|
$price_base_type = $prod->price_base_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,9 +351,9 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$desc = $prod->description;
|
$desc = $prod->description;
|
||||||
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
|
$desc.= $prod->description && $_POST['np_desc'] ? "\n" : "";
|
||||||
$desc.= $_POST['np_desc'];
|
$desc.= $_POST['np_desc'];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -374,7 +374,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
'',
|
'',
|
||||||
$price_base_type,
|
$price_base_type,
|
||||||
$pu_ttc
|
$pu_ttc
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
@ -387,7 +387,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $commande->error;
|
$mesg='<div class="error">'.$commande->error.'</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -832,6 +832,20 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
if ($_REQUEST['lang_id'])
|
||||||
|
{
|
||||||
|
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
|
||||||
|
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||||
|
}
|
||||||
|
facture_pdf_create($db, $fac->id, $fac->modelpdf, $outputlangs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$fac->error.'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
$_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition
|
$_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,50 +167,124 @@ if ($_POST["action"] == 'classin')
|
|||||||
|
|
||||||
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
|
if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer)
|
||||||
{
|
{
|
||||||
if ($_POST["pqty"] && (($_POST["pu"] && $_POST["desc"]) || $_POST["p_idprod"]))
|
if ($_POST["pqty"] && (($_POST["pu"] != '' && $_POST["desc"]) || $_POST["p_idprod"]))
|
||||||
{
|
{
|
||||||
$result = 0;
|
|
||||||
$contrat = new Contrat($db);
|
$contrat = new Contrat($db);
|
||||||
$result=$contrat->fetch($_GET["id"]);
|
$ret=$contrat->fetch($_GET["id"]);
|
||||||
if ($_POST["p_idprod"] > 0 && $_POST["mode"]=='predefined')
|
if ($ret < 0)
|
||||||
|
{
|
||||||
|
dolibarr_print_error($db,$commande->error);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$ret=$contrat->fetch_client();
|
||||||
|
|
||||||
|
$date_start='';
|
||||||
|
$date_end='';
|
||||||
|
// Si ajout champ produit libre
|
||||||
|
if ($_POST['mode'] == 'libre')
|
||||||
|
{
|
||||||
|
if ($_POST['date_start_slyear'] && $_POST['date_start_slmonth'] && $_POST['date_start_slday'])
|
||||||
|
{
|
||||||
|
$date_start=dolibarr_mktime(12,0,0,$_POST['date_start_slmonth'],$_POST['date_start_slday'],$_POST['date_start_slyear']);
|
||||||
|
}
|
||||||
|
if ($_POST['date_end_slyear'] && $_POST['date_end_slmonth'] && $_POST['date_end_slday'])
|
||||||
|
{
|
||||||
|
$date_end=dolibarr_mktime(12,0,0,$_POST['date_end_slmonth'],$_POST['date_end_slday'],$_POST['date_end_slyear']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Si ajout champ produit prédéfini
|
||||||
|
if ($_POST['mode'] == 'predefined')
|
||||||
|
{
|
||||||
|
if ($_POST['date_startyear'] && $_POST['date_startmonth'] && $_POST['date_startday'])
|
||||||
|
{
|
||||||
|
$date_start=dolibarr_mktime(12,0,0,$_POST['date_startmonth'],$_POST['date_startday'],$_POST['date_startyear']);
|
||||||
|
}
|
||||||
|
if ($_POST['date_endyear'] && $_POST['date_endmonth'] && $_POST['date_endday'])
|
||||||
|
{
|
||||||
|
$date_end=dolibarr_mktime(12,0,0,$_POST['date_endmonth'],$_POST['date_endday'],$_POST['date_endmonth']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$price_base_type = 'HT';
|
||||||
|
|
||||||
|
// Ecrase $pu par celui du produit
|
||||||
|
// Ecrase $desc par celui du produit
|
||||||
|
// Ecrase $txtva par celui du produit
|
||||||
|
// Ecrase $base_price_type par celui du produit
|
||||||
|
if ($_POST['p_idprod'])
|
||||||
{
|
{
|
||||||
//print $_POST["desc"]." - ".$_POST["pu"]." - ".$_POST["pqty"]." - ".$_POST["tva_tx"]." - ".$_POST["p_idprod"]." - ".$_POST["premise"]; exit;
|
$prod = new Product($db, $_POST['p_idprod']);
|
||||||
$result = $contrat->addline(
|
$prod->fetch($_POST['p_idprod']);
|
||||||
$_POST["desc"],
|
|
||||||
$_POST["pu"],
|
$tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx);
|
||||||
|
|
||||||
|
// On defini prix unitaire
|
||||||
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
|
{
|
||||||
|
$pu_ht = $prod->multiprices[$fac->client->price_level];
|
||||||
|
$pu_ttc = $prod->multiprices_ttc[$fac->client->price_level];
|
||||||
|
$price_base_type = $prod->multiprices_base_type[$fac->client->price_level];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ht = $prod->price;
|
||||||
|
$pu_ttc = $prod->price_ttc;
|
||||||
|
$price_base_type = $prod->price_base_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On reevalue prix selon taux tva car taux tva transaction peut etre different
|
||||||
|
// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
|
||||||
|
if ($tva_tx != $prod->tva_tx)
|
||||||
|
{
|
||||||
|
if ($price_base_type != 'HT')
|
||||||
|
{
|
||||||
|
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$desc = $prod->description;
|
||||||
|
$desc.= $prod->description && $_POST['desc'] ? "\n" : "";
|
||||||
|
$desc.= $_POST['desc'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$pu_ht=$_POST['pu'];
|
||||||
|
$tva_tx=$_POST['tva_tx'];
|
||||||
|
$desc=$_POST['desc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $contrat->addline(
|
||||||
|
$desc,
|
||||||
|
$pu_ht,
|
||||||
$_POST["pqty"],
|
$_POST["pqty"],
|
||||||
$_POST["tva_tx"],
|
$tva_tx,
|
||||||
$_POST["p_idprod"],
|
$_POST["p_idprod"],
|
||||||
$_POST["premise"],
|
$_POST["premise"],
|
||||||
$date_start,
|
$date_start,
|
||||||
$date_end,
|
$date_end,
|
||||||
'HT'
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
);
|
);
|
||||||
}
|
|
||||||
elseif ($_POST["mode"]=='libre')
|
|
||||||
{
|
|
||||||
$result = $contrat->addline(
|
|
||||||
$_POST["desc"],
|
|
||||||
$_POST["pu"],
|
|
||||||
$_POST["pqty"],
|
|
||||||
$_POST["tva_tx"],
|
|
||||||
0,
|
|
||||||
$_POST["premise"],
|
|
||||||
$date_start_sl,
|
|
||||||
$date_end_sl,
|
|
||||||
'HT'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result >= 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
Header("Location: fiche.php?id=".$contrat->id);
|
/*
|
||||||
exit;
|
if ($_REQUEST['lang_id'])
|
||||||
}
|
{
|
||||||
else
|
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
|
||||||
{
|
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
|
||||||
|
}
|
||||||
|
contrat_pdf_create($db, $contrat->id, $contrat->modelpdf, $outputlangs);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$mesg='<div class="error">'.$contrat->error.'</div>';
|
$mesg='<div class="error">'.$contrat->error.'</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user