26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/cashdesk/include/environnement.php';
28 require_once DOL_DOCUMENT_ROOT.
'/cashdesk/class/Facturation.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 $action =
GETPOST(
'action',
'aZ09');
34 $obj_facturation = unserialize($_SESSION[
'serObjFacturation']);
35 unset($_SESSION[
'serObjFacturation']);
41 if ($_POST[
'hdnSource'] !=
'NULL')
43 $sql =
"SELECT p.rowid, p.ref, p.price, p.tva_tx, p.default_vat_code, p.recuperableonly";
44 if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql .=
", ps.reel";
45 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
46 if (!empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = ".$conf_fkentrepot;
47 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
50 if ($_POST[
'hdnSource'] ==
'LISTE')
52 $sql .=
" AND p.rowid = ".((int)
GETPOST(
'selProduit',
'int'));
53 } elseif ($_POST[
'hdnSource'] ==
'REF')
55 $sql .=
" AND p.ref = '".$db->escape(
GETPOST(
'txtRef',
'alpha')).
"'";
58 $result = $db->query($sql);
62 if ($db->num_rows($result))
65 $tab = $db->fetch_array($result);
66 foreach ($tab as $key => $value)
72 $productid = $ret[
'rowid'];
74 $product->fetch($productid);
77 $thirdpartyid = $_SESSION[
'CASHDESK_ID_THIRDPARTY'];
79 $societe->fetch($thirdpartyid);
84 if (empty($tva_tx)) $tva_npr = 0;
86 $pu_ht = $prod->price;
87 $pu_ttc = $prod->price_ttc;
88 $price_min = $prod->price_min;
89 $price_base_type = $prod->price_base_type;
92 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($societe->price_level))
94 $pu_ht = $prod->multiprices[$societe->price_level];
95 $pu_ttc = $prod->multiprices_ttc[$societe->price_level];
96 $price_min = $prod->multiprices_min[$societe->price_level];
97 $price_base_type = $prod->multiprices_base_type[$societe->price_level];
98 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL))
100 if (isset($prod->multiprices_tva_tx[$societe->price_level])) $tva_tx = $prod->multiprices_tva_tx[$societe->price_level];
101 if (isset($prod->multiprices_recuperableonly[$societe->price_level])) $tva_npr = $prod->multiprices_recuperableonly[$societe->price_level];
103 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES))
105 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
109 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $societe->id);
111 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
114 if (count($prodcustprice->lines) > 0)
116 $pu_ht =
price($prodcustprice->lines[0]->price);
117 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
118 $price_base_type = $prodcustprice->lines[0]->price_base_type;
119 $tva_tx = $prodcustprice->lines[0]->tva_tx;
120 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
121 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
122 if (empty($tva_tx)) $tva_npr = 0;
129 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
130 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
133 if (!empty($price_ht)) {
135 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
139 elseif ($tmpvat != $tmpprodvat) {
140 if ($price_base_type !=
'HT') {
141 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
143 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
147 $obj_facturation->id($ret[
'rowid']);
148 $obj_facturation->ref($ret[
'ref']);
149 $obj_facturation->stock($ret[
'reel']);
151 $obj_facturation->prix($pu_ht);
155 $obj_facturation->vatrate = $vatrate;
158 if ($_POST[
'hdnSource'] ==
'LISTE')
160 $filtre = $ret[
'ref'];
161 } elseif ($_POST[
'hdnSource'] ==
'REF')
163 $filtre = $_POST[
'txtRef'];
166 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation&filtre='.$filtre;
168 $obj_facturation->raz();
170 if ($_POST[
'hdnSource'] ==
'REF')
172 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation&filtre='.$_POST[
'txtRef'];
174 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation';
181 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation';
186 case 'change_thirdparty':
187 $newthirdpartyid =
GETPOST(
'CASHDESK_ID_THIRDPARTY',
'int');
188 if ($newthirdpartyid > 0)
190 $_SESSION[
"CASHDESK_ID_THIRDPARTY"] = $newthirdpartyid;
193 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation';
196 case 'ajout_article':
198 if (!empty($obj_facturation->id))
200 dol_syslog(
"facturation_verif save vat ".$_POST[
'selTva']);
201 $obj_facturation->qte($_POST[
'txtQte']);
202 $obj_facturation->tva($_POST[
'selTva']);
203 $obj_facturation->remisePercent($_POST[
'txtRemise']);
204 $obj_facturation->ajoutArticle();
208 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation';
211 case 'suppr_article':
212 $obj_facturation->supprArticle($_GET[
'suppr_id']);
214 $redirection = DOL_URL_ROOT.
'/cashdesk/affIndex.php?menutpl=facturation';
219 $_SESSION[
'serObjFacturation'] = serialize($obj_facturation);
221 header(
'Location: '.$redirection);
File of class to manage predefined price products or services by customer.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) Si ...