remx.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/remx.php
  21. * \ingroup societe
  22. * \brief Page to edit absolute discounts for a customer
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('orders', 'bills', 'companies'));
  31. $id=GETPOST('id','int');
  32. $action=GETPOST('action','alpha');
  33. $backtopage=GETPOST('backtopage','alpha');
  34. // Security check
  35. $socid = GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','int');
  36. if ($user->societe_id > 0)
  37. {
  38. $socid = $user->societe_id;
  39. }
  40. /*
  41. * Actions
  42. */
  43. if (GETPOST('cancel','alpha') && ! empty($backtopage))
  44. {
  45. header("Location: ".$backtopage);
  46. exit;
  47. }
  48. if ($action == 'confirm_split' && GETPOST("confirm") == 'yes')
  49. {
  50. //if ($user->rights->societe->creer)
  51. //if ($user->rights->facture->creer)
  52. $amount_ttc_1=GETPOST('amount_ttc_1');
  53. $amount_ttc_2=GETPOST('amount_ttc_2');
  54. $error=0;
  55. $remid=GETPOST("remid")?GETPOST("remid"):0;
  56. $discount=new DiscountAbsolute($db);
  57. $res=$discount->fetch($remid);
  58. if (! $res > 0)
  59. {
  60. $error++;
  61. setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors');
  62. }
  63. if (! $error && price2num($amount_ttc_1+$amount_ttc_2) != $discount->amount_ttc)
  64. {
  65. $error++;
  66. setEventMessages($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), null, 'errors');
  67. }
  68. if (! $error && $discount->fk_facture_line)
  69. {
  70. $error++;
  71. setEventMessages($langs->trans("ErrorCantSplitAUsedDiscount"), null, 'errors');
  72. }
  73. if (! $error)
  74. {
  75. $newdiscount1=new DiscountAbsolute($db);
  76. $newdiscount2=new DiscountAbsolute($db);
  77. $newdiscount1->fk_facture_source=$discount->fk_facture_source;
  78. $newdiscount2->fk_facture_source=$discount->fk_facture_source;
  79. $newdiscount1->fk_facture=$discount->fk_facture;
  80. $newdiscount2->fk_facture=$discount->fk_facture;
  81. $newdiscount1->fk_facture_line=$discount->fk_facture_line;
  82. $newdiscount2->fk_facture_line=$discount->fk_facture_line;
  83. $newdiscount1->fk_invoice_supplier_source=$discount->fk_invoice_supplier_source;
  84. $newdiscount2->fk_invoice_supplier_source=$discount->fk_invoice_supplier_source;
  85. $newdiscount1->fk_invoice_supplier=$discount->fk_invoice_supplier;
  86. $newdiscount2->fk_invoice_supplier=$discount->fk_invoice_supplier;
  87. $newdiscount1->fk_invoice_supplier_line=$discount->fk_invoice_supplier_line;
  88. $newdiscount2->fk_invoice_supplier_line=$discount->fk_invoice_supplier_line;
  89. if ($discount->description == '(CREDIT_NOTE)' || $discount->description == '(DEPOSIT)')
  90. {
  91. $newdiscount1->description=$discount->description;
  92. $newdiscount2->description=$discount->description;
  93. }
  94. else
  95. {
  96. $newdiscount1->description=$discount->description.' (1)';
  97. $newdiscount2->description=$discount->description.' (2)';
  98. }
  99. $newdiscount1->fk_user=$discount->fk_user;
  100. $newdiscount2->fk_user=$discount->fk_user;
  101. $newdiscount1->fk_soc=$discount->fk_soc;
  102. $newdiscount2->fk_soc=$discount->fk_soc;
  103. $newdiscount1->discount_type=$discount->discount_type;
  104. $newdiscount2->discount_type=$discount->discount_type;
  105. $newdiscount1->datec=$discount->datec;
  106. $newdiscount2->datec=$discount->datec;
  107. $newdiscount1->tva_tx=$discount->tva_tx;
  108. $newdiscount2->tva_tx=$discount->tva_tx;
  109. $newdiscount1->amount_ttc=$_POST["amount_ttc_1"];
  110. $newdiscount2->amount_ttc=price2num($discount->amount_ttc-$newdiscount1->amount_ttc);
  111. $newdiscount1->amount_ht=price2num($newdiscount1->amount_ttc/(1+$newdiscount1->tva_tx/100),'MT');
  112. $newdiscount2->amount_ht=price2num($newdiscount2->amount_ttc/(1+$newdiscount2->tva_tx/100),'MT');
  113. $newdiscount1->amount_tva=price2num($newdiscount1->amount_ttc-$newdiscount1->amount_ht);
  114. $newdiscount2->amount_tva=price2num($newdiscount2->amount_ttc-$newdiscount2->amount_ht);
  115. $db->begin();
  116. $discount->fk_facture_source=0; // This is to delete only the require record (that we will recreate with two records) and not all family with same fk_facture_source
  117. $res=$discount->delete($user);
  118. $newid1=$newdiscount1->create($user);
  119. $newid2=$newdiscount2->create($user);
  120. if ($res > 0 && $newid1 > 0 && $newid2 > 0)
  121. {
  122. $db->commit();
  123. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id.($backtopage?'&backtopage='.urlencode($backtopage):'')); // To avoid pb whith back
  124. exit;
  125. }
  126. else
  127. {
  128. $db->rollback();
  129. }
  130. }
  131. }
  132. if ($action == 'setremise' && $user->rights->societe->creer)
  133. {
  134. //if ($user->rights->societe->creer)
  135. //if ($user->rights->facture->creer)
  136. $amount_ht=GETPOST('amount_ht');
  137. $desc=GETPOST('desc','alpha');
  138. $tva_tx=GETPOST('tva_tx','alpha');
  139. $discount_type=! empty($_POST['discount_type'])?GETPOST('discount_type','alpha'):0;
  140. if (price2num($amount_ht) > 0)
  141. {
  142. $error=0;
  143. if (empty($desc))
  144. {
  145. setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("ReasonDiscount")), null, 'errors');
  146. $error++;
  147. }
  148. if (! $error)
  149. {
  150. $soc = new Societe($db);
  151. $soc->fetch($id);
  152. $discountid=$soc->set_remise_except($amount_ht,$user,$desc,$tva_tx,$discount_type);
  153. if ($discountid > 0)
  154. {
  155. if (! empty($backtopage))
  156. {
  157. header("Location: ".$backtopage.'&discountid='.$discountid);
  158. exit;
  159. }
  160. else
  161. {
  162. header("Location: remx.php?id=".$id);
  163. exit;
  164. }
  165. }
  166. else
  167. {
  168. $error++;
  169. setEventMessages($soc->error, $soc->errors, 'errors');
  170. }
  171. }
  172. }
  173. else
  174. {
  175. setEventMessages($langs->trans("ErrorFieldFormat",$langs->trans("NewGlobalDiscount")), null, 'errors');
  176. }
  177. }
  178. if (GETPOST('action','aZ09') == 'confirm_remove' && GETPOST("confirm")=='yes')
  179. {
  180. //if ($user->rights->societe->creer)
  181. //if ($user->rights->facture->creer)
  182. $db->begin();
  183. $discount = new DiscountAbsolute($db);
  184. $result=$discount->fetch(GETPOST("remid"));
  185. $result=$discount->delete($user);
  186. if ($result > 0)
  187. {
  188. $db->commit();
  189. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); // To avoid pb whith back
  190. exit;
  191. }
  192. else
  193. {
  194. setEventMessages($discount->error, $discount->errors, 'errors');
  195. $db->rollback();
  196. }
  197. }
  198. /*
  199. * View
  200. */
  201. $form=new Form($db);
  202. $facturestatic=new Facture($db);
  203. $facturefournstatic=new FactureFournisseur($db);
  204. llxHeader('',$langs->trans("GlobalDiscount"));
  205. if ($socid > 0)
  206. {
  207. // On recupere les donnees societes par l'objet
  208. $object = new Societe($db);
  209. $object->fetch($socid);
  210. $isCustomer = $object->client == 1 || $object->client == 3;
  211. $isSupplier = $object->fournisseur == 1;
  212. /*
  213. * Display tabs
  214. */
  215. $head = societe_prepare_head($object);
  216. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  217. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  218. print '<input type="hidden" name="action" value="setremise">';
  219. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  220. dol_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"), 0, 'company');
  221. dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
  222. print '<div class="fichecenter">';
  223. print '<div class="underbanner clearboth"></div>';
  224. if(! $isCustomer && ! $isSupplier) {
  225. print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
  226. dol_fiche_end();
  227. print '</form>';
  228. llxFooter();
  229. $db->close();
  230. exit;
  231. }
  232. print '<table class="border centpercent">';
  233. if($isCustomer) { // Calcul avoirs client en cours
  234. $remise_all=$remise_user=0;
  235. $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
  236. $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
  237. $sql.= " WHERE rc.fk_soc = " . $object->id;
  238. $sql.= " AND rc.entity = " . $conf->entity;
  239. $sql.= " AND discount_type = 0"; // Exclude supplier discounts
  240. $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
  241. $sql.= " GROUP BY rc.fk_user";
  242. $resql=$db->query($sql);
  243. if ($resql)
  244. {
  245. $obj = $db->fetch_object($resql);
  246. $remise_all+=$obj->amount;
  247. if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
  248. }
  249. else
  250. {
  251. dol_print_error($db);
  252. }
  253. print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
  254. print '<td>'.$remise_all.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  255. if (! empty($user->fk_soc)) // No need to show this for external users
  256. {
  257. print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
  258. print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  259. }
  260. }
  261. if($isSupplier) {
  262. // Calcul avoirs fournisseur en cours
  263. $remise_all=$remise_user=0;
  264. $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
  265. $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
  266. $sql.= " WHERE rc.fk_soc = " . $object->id;
  267. $sql.= " AND rc.entity = " . $conf->entity;
  268. $sql.= " AND discount_type = 1"; // Exclude customer discounts
  269. $sql.= " AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
  270. $sql.= " GROUP BY rc.fk_user";
  271. $resql=$db->query($sql);
  272. if ($resql)
  273. {
  274. $obj = $db->fetch_object($resql);
  275. $remise_all+=$obj->amount;
  276. if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
  277. }
  278. else
  279. {
  280. dol_print_error($db);
  281. }
  282. print '<tr><td class="titlefield">'.$langs->trans("SupplierAbsoluteDiscountAllUsers").'</td>';
  283. print '<td>'.$remise_all.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  284. if (! empty($user->fk_soc)) // No need to show this for external users
  285. {
  286. print '<tr><td>'.$langs->trans("SupplierAbsoluteDiscountMy").'</td>';
  287. print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  288. }
  289. }
  290. print '</table>';
  291. print '</div>';
  292. if ($user->rights->societe->creer)
  293. {
  294. print '<br>';
  295. print load_fiche_titre($langs->trans("NewGlobalDiscount"),'','');
  296. print '<div class="underbanner clearboth"></div>';
  297. if($isCustomer && ! $isSupplier) {
  298. print '<input type="hidden" name="discount_type" value="0" />';
  299. }
  300. if(! $isCustomer && $isSupplier) {
  301. print '<input type="hidden" name="discount_type" value="1" />';
  302. }
  303. print '<table class="border" width="100%">';
  304. if($isCustomer && $isSupplier) {
  305. print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
  306. print '<td><input type="radio" name="discount_type" id="discount_type_0" checked="checked" value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
  307. print ' &nbsp; <input type="radio" name="discount_type" id="discount_type_1" value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
  308. print '</td></tr>';
  309. }
  310. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("AmountHT").'</td>';
  311. print '<td><input type="text" size="5" name="amount_ht" value="'.price2num(GETPOST("amount_ht")).'">';
  312. print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  313. print '<tr><td>'.$langs->trans("VAT").'</td>';
  314. print '<td>';
  315. print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object);
  316. print '</td></tr>';
  317. print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
  318. print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST('desc','none').'"></td></tr>';
  319. print "</table>";
  320. }
  321. dol_fiche_end();
  322. if ($user->rights->societe->creer)
  323. {
  324. print '<div class="center">';
  325. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
  326. if (! empty($backtopage))
  327. {
  328. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  329. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  330. }
  331. print '</div>';
  332. }
  333. print '</form>';
  334. print '<br>';
  335. if ($_GET['action'] == 'remove')
  336. {
  337. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
  338. }
  339. /*
  340. * Liste remises fixes client restant en cours (= liees a aucune facture ni ligne de facture)
  341. */
  342. print load_fiche_titre($langs->trans("DiscountStillRemaining"));
  343. if($isCustomer) {
  344. if($isSupplier) {
  345. print '<div class="fichecenter">';
  346. print '<div class="fichehalfleft">';
  347. print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
  348. }
  349. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  350. $sql.= " rc.datec as dc, rc.description,";
  351. $sql.= " rc.fk_facture_source,";
  352. $sql.= " u.login, u.rowid as user_id,";
  353. $sql.= " fa.facnumber as ref, fa.type as type";
  354. $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
  355. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  356. $sql.= " WHERE rc.fk_soc = " . $object->id;
  357. $sql.= " AND rc.entity = " . $conf->entity;
  358. $sql.= " AND u.rowid = rc.fk_user";
  359. $sql.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
  360. $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
  361. $sql.= " ORDER BY rc.datec DESC";
  362. $resql=$db->query($sql);
  363. if ($resql)
  364. {
  365. print '<div class="div-table-responsive-no-min">';
  366. print '<table width="100%" class="noborder">';
  367. print '<tr class="liste_titre">';
  368. print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  369. print '<td>'.$langs->trans("ReasonDiscount").'</td>';
  370. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  371. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  372. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  373. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  374. print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
  375. print '<td width="50">&nbsp;</td>';
  376. print '</tr>';
  377. $showconfirminfo=array();
  378. $i = 0;
  379. $num = $db->num_rows($resql);
  380. if ($num > 0)
  381. {
  382. while ($i < $num)
  383. {
  384. $obj = $db->fetch_object($resql);
  385. print '<tr class="oddeven">';
  386. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  387. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  388. {
  389. print '<td class="nowrap">';
  390. $facturestatic->id=$obj->fk_facture_source;
  391. $facturestatic->ref=$obj->ref;
  392. $facturestatic->type=$obj->type;
  393. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
  394. print '</td>';
  395. }
  396. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  397. {
  398. print '<td class="nowrap">';
  399. $facturestatic->id=$obj->fk_facture_source;
  400. $facturestatic->ref=$obj->ref;
  401. $facturestatic->type=$obj->type;
  402. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
  403. print '</td>';
  404. }
  405. elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
  406. {
  407. print '<td class="nowrap">';
  408. $facturestatic->id=$obj->fk_facture_source;
  409. $facturestatic->ref=$obj->ref;
  410. $facturestatic->type=$obj->type;
  411. print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("ExcessReceived"),$obj->description).' '.$facturestatic->getNomURl(1);
  412. print '</td>';
  413. }
  414. else
  415. {
  416. print '<td>';
  417. print $obj->description;
  418. print '</td>';
  419. }
  420. print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
  421. print '<td align="right">'.price($obj->amount_ht).'</td>';
  422. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  423. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  424. print '<td align="center">';
  425. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  426. print '</td>';
  427. if ($user->rights->societe->creer || $user->rights->facture->creer)
  428. {
  429. print '<td class="nowrap">';
  430. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=split&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).'</a>';
  431. print ' &nbsp; ';
  432. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
  433. print '</td>';
  434. }
  435. else print '<td>&nbsp;</td>';
  436. print '</tr>';
  437. if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
  438. {
  439. $showconfirminfo['rowid']=$obj->rowid;
  440. $showconfirminfo['amount_ttc']=$obj->amount_ttc;
  441. }
  442. $i++;
  443. }
  444. }
  445. else
  446. {
  447. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  448. }
  449. $db->free($resql);
  450. print "</table>";
  451. print '</div>';
  452. if (count($showconfirminfo))
  453. {
  454. $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
  455. $amount2=($showconfirminfo['amount_ttc']-$amount1);
  456. $formquestion=array(
  457. 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
  458. array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
  459. array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
  460. );
  461. $langs->load("dict");
  462. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
  463. }
  464. }
  465. else
  466. {
  467. dol_print_error($db);
  468. }
  469. }
  470. if($isSupplier) {
  471. if($isCustomer) {
  472. print '</div>'; // class="fichehalfleft"
  473. print '<div class="fichehalfright">';
  474. print '<div class="ficheaddleft">';
  475. print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
  476. }
  477. /*
  478. * Liste remises fixes fournisseur restant en cours (= liees a aucune facture ni ligne de facture)
  479. */
  480. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  481. $sql.= " rc.datec as dc, rc.description,";
  482. $sql.= " rc.fk_invoice_supplier_source,";
  483. $sql.= " u.login, u.rowid as user_id,";
  484. $sql.= " fa.ref, fa.type as type";
  485. $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
  486. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
  487. $sql.= " WHERE rc.fk_soc = " . $object->id;
  488. $sql.= " AND rc.entity = " . $conf->entity;
  489. $sql.= " AND u.rowid = rc.fk_user";
  490. $sql.= " AND rc.discount_type = 1"; // Eliminate customer discounts
  491. $sql.= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
  492. $sql.= " ORDER BY rc.datec DESC";
  493. $resql=$db->query($sql);
  494. if ($resql)
  495. {
  496. print '<div class="div-table-responsive-no-min">';
  497. print '<table width="100%" class="noborder">';
  498. print '<tr class="liste_titre">';
  499. print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  500. print '<td>'.$langs->trans("ReasonDiscount").'</td>';
  501. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  502. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  503. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  504. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  505. print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
  506. print '<td width="50">&nbsp;</td>';
  507. print '</tr>';
  508. $showconfirminfo=array();
  509. $i = 0;
  510. $num = $db->num_rows($resql);
  511. if ($num > 0)
  512. {
  513. while ($i < $num)
  514. {
  515. $obj = $db->fetch_object($resql);
  516. print '<tr class="oddeven">';
  517. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  518. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  519. {
  520. print '<td class="nowrap">';
  521. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  522. $facturefournstatic->ref=$obj->ref;
  523. $facturefournstatic->type=$obj->type;
  524. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  525. print '</td>';
  526. }
  527. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  528. {
  529. print '<td class="nowrap">';
  530. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  531. $facturefournstatic->ref=$obj->ref;
  532. $facturefournstatic->type=$obj->type;
  533. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  534. print '</td>';
  535. }
  536. elseif (preg_match('/\(EXCESS PAID\)/',$obj->description))
  537. {
  538. print '<td class="nowrap">';
  539. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  540. $facturefournstatic->ref=$obj->ref;
  541. $facturefournstatic->type=$obj->type;
  542. print preg_replace('/\(EXCESS PAID\)/',$langs->trans("ExcessPaid"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  543. print '</td>';
  544. }
  545. else
  546. {
  547. print '<td>';
  548. print $obj->description;
  549. print '</td>';
  550. }
  551. print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
  552. print '<td align="right">'.price($obj->amount_ht).'</td>';
  553. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  554. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  555. print '<td align="center">';
  556. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  557. print '</td>';
  558. if ($user->rights->societe->creer || $user->rights->facture->creer)
  559. {
  560. print '<td class="nowrap">';
  561. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=split&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_split($langs->trans("SplitDiscount")).'</a>';
  562. print ' &nbsp; ';
  563. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&remid='.$obj->rowid.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
  564. print '</td>';
  565. }
  566. else print '<td>&nbsp;</td>';
  567. print '</tr>';
  568. if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
  569. {
  570. $showconfirminfo['rowid']=$obj->rowid;
  571. $showconfirminfo['amount_ttc']=$obj->amount_ttc;
  572. }
  573. $i++;
  574. }
  575. }
  576. else
  577. {
  578. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  579. }
  580. $db->free($resql);
  581. print "</table>";
  582. print '</div>';
  583. if (count($showconfirminfo))
  584. {
  585. $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
  586. $amount2=($showconfirminfo['amount_ttc']-$amount1);
  587. $formquestion=array(
  588. 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
  589. array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
  590. array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
  591. );
  592. $langs->load("dict");
  593. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].($backtopage?'&backtopage='.urlencode($backtopage):''), $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
  594. }
  595. }
  596. else
  597. {
  598. dol_print_error($db);
  599. }
  600. if ($isCustomer) {
  601. print '</div>'; // class="ficheaddleft"
  602. print '</div>'; // class="fichehalfright"
  603. print '</div>'; // class="fichecenter"
  604. }
  605. }
  606. print '<div class="clearboth"></div><br>';
  607. /*
  608. * List discount consumed (=liees a une ligne de facture ou facture)
  609. */
  610. print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
  611. if($isCustomer) {
  612. if($isSupplier) {
  613. print '<div class="fichecenter">';
  614. print '<div class="fichehalfleft">';
  615. print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
  616. }
  617. // Remises liees a lignes de factures
  618. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  619. $sql.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
  620. $sql.= " rc.fk_facture_source,";
  621. $sql.= " u.login, u.rowid as user_id,";
  622. $sql.= " f.rowid, f.facnumber,";
  623. $sql.= " fa.facnumber as ref, fa.type as type";
  624. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  625. $sql.= " , ".MAIN_DB_PREFIX."user as u";
  626. $sql.= " , ".MAIN_DB_PREFIX."facturedet as fc";
  627. $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  628. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  629. $sql.= " WHERE rc.fk_soc =". $object->id;
  630. $sql.= " AND rc.fk_facture_line = fc.rowid";
  631. $sql.= " AND fc.fk_facture = f.rowid";
  632. $sql.= " AND rc.fk_user = u.rowid";
  633. $sql.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
  634. $sql.= " ORDER BY dc DESC";
  635. //$sql.= " UNION ";
  636. // Remises liees a factures
  637. $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  638. $sql2.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
  639. $sql2.= " rc.fk_facture_source,";
  640. $sql2.= " u.login, u.rowid as user_id,";
  641. $sql2.= " f.rowid, f.facnumber,";
  642. $sql2.= " fa.facnumber as ref, fa.type as type";
  643. $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f";
  644. $sql2.= " , ".MAIN_DB_PREFIX."user as u";
  645. $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  646. $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  647. $sql2.= " WHERE rc.fk_soc =". $object->id;
  648. $sql2.= " AND rc.fk_facture = f.rowid";
  649. $sql2.= " AND rc.fk_user = u.rowid";
  650. $sql2.= " AND rc.discount_type = 0"; // Eliminate supplier discounts
  651. $sql2.= " ORDER BY dc DESC";
  652. $resql=$db->query($sql);
  653. $resql2=null;
  654. if ($resql) $resql2=$db->query($sql2);
  655. if ($resql2)
  656. {
  657. print '<div class="div-table-responsive-no-min">';
  658. print '<table class="noborder" width="100%">';
  659. print '<tr class="liste_titre">';
  660. print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  661. print '<td>'.$langs->trans("ReasonDiscount").'</td>';
  662. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  663. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  664. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  665. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  666. print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
  667. print '<td width="50">&nbsp;</td>';
  668. print '</tr>';
  669. $tab_sqlobj=array();
  670. $tab_sqlobjOrder=array();
  671. $num = $db->num_rows($resql);
  672. if ($num > 0)
  673. {
  674. for ($i = 0;$i < $num; $i++)
  675. {
  676. $sqlobj = $db->fetch_object($resql);
  677. $tab_sqlobj[] = $sqlobj;
  678. $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
  679. }
  680. }
  681. $db->free($resql);
  682. $num = $db->num_rows($resql2);
  683. for ($i = 0;$i < $num;$i++)
  684. {
  685. $sqlobj = $db->fetch_object($resql2);
  686. $tab_sqlobj[] = $sqlobj;
  687. $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
  688. }
  689. $db->free($resql2);
  690. array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
  691. $num = count($tab_sqlobj);
  692. if ($num > 0)
  693. {
  694. $i = 0 ;
  695. while ($i < $num )
  696. {
  697. $obj = array_shift($tab_sqlobj);
  698. print '<tr class="oddeven">';
  699. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  700. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  701. {
  702. print '<td class="nowrap">';
  703. $facturestatic->id=$obj->fk_facture_source;
  704. $facturestatic->ref=$obj->ref;
  705. $facturestatic->type=$obj->type;
  706. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
  707. print '</td>';
  708. }
  709. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  710. {
  711. print '<td class="nowrap">';
  712. $facturestatic->id=$obj->fk_facture_source;
  713. $facturestatic->ref=$obj->ref;
  714. $facturestatic->type=$obj->type;
  715. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
  716. print '</td>';
  717. }
  718. elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
  719. {
  720. print '<td class="nowrap">';
  721. $facturestatic->id=$obj->fk_facture_source;
  722. $facturestatic->ref=$obj->ref;
  723. $facturestatic->type=$obj->type;
  724. print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1);
  725. print '</td>';
  726. }
  727. else
  728. {
  729. print '<td>';
  730. print $obj->description;
  731. print '</td>';
  732. }
  733. print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
  734. print '<td align="right">'.price($obj->amount_ht).'</td>';
  735. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  736. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  737. print '<td align="center">';
  738. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  739. print '</td>';
  740. print '<td>&nbsp;</td>';
  741. print '</tr>';
  742. $i++;
  743. }
  744. }
  745. else
  746. {
  747. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  748. }
  749. print "</table>";
  750. print '</div>';
  751. }
  752. else
  753. {
  754. dol_print_error($db);
  755. }
  756. }
  757. if($isSupplier) {
  758. if($isCustomer) {
  759. print '</div>'; // class="fichehalfleft"
  760. print '<div class="fichehalfright">';
  761. print '<div class="ficheaddleft">';
  762. print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
  763. }
  764. // Remises liees a lignes de factures
  765. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  766. $sql.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
  767. $sql.= " rc.fk_invoice_supplier_source,";
  768. $sql.= " u.login, u.rowid as user_id,";
  769. $sql.= " f.rowid, f.ref as facnumber,";
  770. $sql.= " fa.ref, fa.type as type";
  771. $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  772. $sql.= " , ".MAIN_DB_PREFIX."user as u";
  773. $sql.= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc";
  774. $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  775. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
  776. $sql.= " WHERE rc.fk_soc =". $object->id;
  777. $sql.= " AND rc.fk_invoice_supplier_line = fc.rowid";
  778. $sql.= " AND fc.fk_facture_fourn = f.rowid";
  779. $sql.= " AND rc.fk_user = u.rowid";
  780. $sql.= " AND rc.discount_type = 1"; // Eliminate customer discounts
  781. $sql.= " ORDER BY dc DESC";
  782. //$sql.= " UNION ";
  783. // Remises liees a factures
  784. $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  785. $sql2.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
  786. $sql2.= " rc.fk_invoice_supplier_source,";
  787. $sql2.= " u.login, u.rowid as user_id,";
  788. $sql2.= " f.rowid, f.ref as facnumber,";
  789. $sql2.= " fa.ref, fa.type as type";
  790. $sql2.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
  791. $sql2.= " , ".MAIN_DB_PREFIX."user as u";
  792. $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  793. $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
  794. $sql2.= " WHERE rc.fk_soc =". $object->id;
  795. $sql2.= " AND rc.fk_invoice_supplier = f.rowid";
  796. $sql2.= " AND rc.fk_user = u.rowid";
  797. $sql2.= " AND rc.discount_type = 1"; // Eliminate customer discounts
  798. $sql2.= " ORDER BY dc DESC";
  799. $resql=$db->query($sql);
  800. $resql2=null;
  801. if ($resql) $resql2=$db->query($sql2);
  802. if ($resql2)
  803. {
  804. print '<div class="div-table-responsive-no-min">';
  805. print '<table class="noborder" width="100%">';
  806. print '<tr class="liste_titre">';
  807. print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  808. print '<td>'.$langs->trans("ReasonDiscount").'</td>';
  809. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  810. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  811. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  812. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  813. print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
  814. print '<td width="50">&nbsp;</td>';
  815. print '</tr>';
  816. $tab_sqlobj=array();
  817. $tab_sqlobjOrder=array();
  818. $num = $db->num_rows($resql);
  819. if ($num > 0)
  820. {
  821. for ($i = 0;$i < $num; $i++)
  822. {
  823. $sqlobj = $db->fetch_object($resql);
  824. $tab_sqlobj[] = $sqlobj;
  825. $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
  826. }
  827. }
  828. $db->free($resql);
  829. $num = $db->num_rows($resql2);
  830. for ($i = 0;$i < $num;$i++)
  831. {
  832. $sqlobj = $db->fetch_object($resql2);
  833. $tab_sqlobj[] = $sqlobj;
  834. $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
  835. }
  836. $db->free($resql2);
  837. array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
  838. $num = count($tab_sqlobj);
  839. if ($num > 0)
  840. {
  841. $i = 0 ;
  842. while ($i < $num )
  843. {
  844. $obj = array_shift($tab_sqlobj);
  845. print '<tr class="oddeven">';
  846. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  847. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  848. {
  849. print '<td class="nowrap">';
  850. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  851. $facturefournstatic->ref=$obj->ref;
  852. $facturefournstatic->type=$obj->type;
  853. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  854. print '</td>';
  855. }
  856. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  857. {
  858. print '<td class="nowrap">';
  859. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  860. $facturefournstatic->ref=$obj->ref;
  861. $facturefournstatic->type=$obj->type;
  862. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  863. print '</td>';
  864. }
  865. elseif (preg_match('/\(EXCESS PAID\)/',$obj->description))
  866. {
  867. print '<td class="nowrap">';
  868. $facturefournstatic->id=$obj->fk_invoice_supplier_source;
  869. $facturefournstatic->ref=$obj->ref;
  870. $facturefournstatic->type=$obj->type;
  871. print preg_replace('/\(EXCESS PAID\)/',$langs->trans("Invoice"),$obj->description).' '.$facturefournstatic->getNomURl(1);
  872. print '</td>';
  873. }
  874. else
  875. {
  876. print '<td>';
  877. print $obj->description;
  878. print '</td>';
  879. }
  880. print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
  881. print '<td align="right">'.price($obj->amount_ht).'</td>';
  882. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  883. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  884. print '<td align="center">';
  885. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  886. print '</td>';
  887. print '<td>&nbsp;</td>';
  888. print '</tr>';
  889. $i++;
  890. }
  891. }
  892. else
  893. {
  894. print '<tr><td colspan="8" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  895. }
  896. print "</table>";
  897. print '</div>';
  898. }
  899. else
  900. {
  901. dol_print_error($db);
  902. }
  903. if($isCustomer) {
  904. print '</div>'; // class="ficheaddleft"
  905. print '</div>'; // class="fichehalfright"
  906. print '</div>'; // class="fichecenter"
  907. }
  908. }
  909. }
  910. // End of page
  911. llxFooter();
  912. $db->close();