remx.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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.'/core/class/discount.class.php';
  28. $langs->load("orders");
  29. $langs->load("bills");
  30. $langs->load("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') && ! 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. if ($discount->description == '(CREDIT_NOTE)')
  84. {
  85. $newdiscount1->description=$discount->description;
  86. $newdiscount2->description=$discount->description;
  87. }
  88. else
  89. {
  90. $newdiscount1->description=$discount->description.' (1)';
  91. $newdiscount2->description=$discount->description.' (2)';
  92. }
  93. $newdiscount1->fk_user=$discount->fk_user;
  94. $newdiscount2->fk_user=$discount->fk_user;
  95. $newdiscount1->fk_soc=$discount->fk_soc;
  96. $newdiscount2->fk_soc=$discount->fk_soc;
  97. $newdiscount1->datec=$discount->datec;
  98. $newdiscount2->datec=$discount->datec;
  99. $newdiscount1->tva_tx=$discount->tva_tx;
  100. $newdiscount2->tva_tx=$discount->tva_tx;
  101. $newdiscount1->amount_ttc=$_POST["amount_ttc_1"];
  102. $newdiscount2->amount_ttc=price2num($discount->amount_ttc-$newdiscount1->amount_ttc);
  103. $newdiscount1->amount_ht=price2num($newdiscount1->amount_ttc/(1+$newdiscount1->tva_tx/100),'MT');
  104. $newdiscount2->amount_ht=price2num($newdiscount2->amount_ttc/(1+$newdiscount2->tva_tx/100),'MT');
  105. $newdiscount1->amount_tva=price2num($newdiscount1->amount_ttc-$newdiscount2->amount_ht);
  106. $newdiscount2->amount_tva=price2num($newdiscount2->amount_ttc-$newdiscount2->amount_ht);
  107. $db->begin();
  108. $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
  109. $res=$discount->delete($user);
  110. $newid1=$newdiscount1->create($user);
  111. $newid2=$newdiscount2->create($user);
  112. if ($res > 0 && $newid1 > 0 && $newid2 > 0)
  113. {
  114. $db->commit();
  115. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); // To avoid pb whith back
  116. exit;
  117. }
  118. else
  119. {
  120. $db->rollback();
  121. }
  122. }
  123. }
  124. if ($action == 'setremise' && $user->rights->societe->creer)
  125. {
  126. //if ($user->rights->societe->creer)
  127. //if ($user->rights->facture->creer)
  128. $amount_ht=GETPOST('amount_ht');
  129. $desc=GETPOST('desc','alpha');
  130. $tva_tx=GETPOST('tva_tx','alpha');
  131. if (price2num($amount_ht) > 0)
  132. {
  133. $error=0;
  134. if (empty($desc))
  135. {
  136. setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("ReasonDiscount")), null, 'errors');
  137. $error++;
  138. }
  139. if (! $error)
  140. {
  141. $soc = new Societe($db);
  142. $soc->fetch($id);
  143. $discountid=$soc->set_remise_except($amount_ht,$user,$desc,$tva_tx);
  144. if ($discountid > 0)
  145. {
  146. if (! empty($backtopage))
  147. {
  148. header("Location: ".$backtopage.'&discountid='.$discountid);
  149. exit;
  150. }
  151. else
  152. {
  153. header("Location: remx.php?id=".$id);
  154. exit;
  155. }
  156. }
  157. else
  158. {
  159. $error++;
  160. setEventMessages($soc->error, $soc->errors, 'errors');
  161. }
  162. }
  163. }
  164. else
  165. {
  166. setEventMessages($langs->trans("ErrorFieldFormat",$langs->trans("NewGlobalDiscount")), null, 'errors');
  167. }
  168. }
  169. if (GETPOST("action") == 'confirm_remove' && GETPOST("confirm")=='yes')
  170. {
  171. //if ($user->rights->societe->creer)
  172. //if ($user->rights->facture->creer)
  173. $db->begin();
  174. $discount = new DiscountAbsolute($db);
  175. $result=$discount->fetch(GETPOST("remid"));
  176. $result=$discount->delete($user);
  177. if ($result > 0)
  178. {
  179. $db->commit();
  180. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); // To avoid pb whith back
  181. exit;
  182. }
  183. else
  184. {
  185. setEventMessages($discount->error, $discount->errors, 'errors');
  186. $db->rollback();
  187. }
  188. }
  189. /*
  190. * View
  191. */
  192. $form=new Form($db);
  193. $facturestatic=new Facture($db);
  194. llxHeader('',$langs->trans("GlobalDiscount"));
  195. if ($socid > 0)
  196. {
  197. // On recupere les donnees societes par l'objet
  198. $object = new Societe($db);
  199. $object->fetch($socid);
  200. /*
  201. * Display tabs
  202. */
  203. $head = societe_prepare_head($object);
  204. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  205. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  206. print '<input type="hidden" name="action" value="setremise">';
  207. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  208. dol_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"),0,'company');
  209. dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
  210. print '<div class="fichecenter">';
  211. print '<div class="underbanner clearboth"></div>';
  212. print '<table class="border centpercent">';
  213. // Calcul avoirs en cours
  214. $remise_all=$remise_user=0;
  215. $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
  216. $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
  217. $sql.= " WHERE rc.fk_soc =". $object->id;
  218. $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
  219. $sql.= " GROUP BY rc.fk_user";
  220. $resql=$db->query($sql);
  221. if ($resql)
  222. {
  223. $obj = $db->fetch_object($resql);
  224. $remise_all+=$obj->amount;
  225. if ($obj->fk_user == $user->id) $remise_user+=$obj->amount;
  226. }
  227. else
  228. {
  229. dol_print_error($db);
  230. }
  231. print '<tr><td class="titlefield">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
  232. print '<td>'.$remise_all.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  233. if (! empty($user->fk_soc)) // No need to show this for external users
  234. {
  235. print '<tr><td>'.$langs->trans("CustomerAbsoluteDiscountMy").'</td>';
  236. print '<td>'.$remise_user.'&nbsp;'.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").'</td></tr>';
  237. }
  238. print '</table>';
  239. if ($user->rights->societe->creer)
  240. {
  241. print '<br>';
  242. print load_fiche_titre($langs->trans("NewGlobalDiscount"),'','');
  243. print '<table class="border" width="100%">';
  244. print '<tr><td width="38%" class="fieldrequired">'.$langs->trans("AmountHT").'</td>';
  245. print '<td><input type="text" size="5" name="amount_ht" value="'.$_POST["amount_ht"].'">';
  246. print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  247. print '<tr><td width="38%">'.$langs->trans("VAT").'</td>';
  248. print '<td>';
  249. print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object);
  250. print '</td></tr>';
  251. print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
  252. print '<td><input type="text" size="60" name="desc" value="'.GETPOST('desc').'"></td></tr>';
  253. print "</table>";
  254. }
  255. print '</div>';
  256. dol_fiche_end();
  257. if ($user->rights->societe->creer)
  258. {
  259. print '<div class="center">';
  260. print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
  261. if (! empty($backtopage))
  262. {
  263. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  264. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  265. }
  266. print '</div>';
  267. }
  268. print '</form>';
  269. print '<br>';
  270. if ($_GET['action'] == 'remove')
  271. {
  272. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
  273. }
  274. /*
  275. * Liste remises fixes restant en cours (= liees a aucune facture ni ligne de facture)
  276. */
  277. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  278. $sql.= " rc.datec as dc, rc.description,";
  279. $sql.= " rc.fk_facture_source,";
  280. $sql.= " u.login, u.rowid as user_id,";
  281. $sql.= " fa.facnumber as ref, fa.type as type";
  282. $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
  283. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  284. $sql.= " WHERE rc.fk_soc =". $object->id;
  285. $sql.= " AND u.rowid = rc.fk_user";
  286. $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
  287. $sql.= " ORDER BY rc.datec DESC";
  288. $resql=$db->query($sql);
  289. if ($resql)
  290. {
  291. print load_fiche_titre($langs->trans("DiscountStillRemaining"));
  292. print '<table width="100%" class="noborder">';
  293. print '<tr class="liste_titre">';
  294. print '<td width="120" align="left">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  295. print '<td align="left">'.$langs->trans("ReasonDiscount").'</td>';
  296. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  297. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  298. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  299. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  300. print '<td width="100" align="center">'.$langs->trans("DiscountOfferedBy").'</td>';
  301. print '<td width="50">&nbsp;</td>';
  302. print '</tr>';
  303. $showconfirminfo=array();
  304. $var = true;
  305. $i = 0;
  306. $num = $db->num_rows($resql);
  307. while ($i < $num)
  308. {
  309. $obj = $db->fetch_object($resql);
  310. $var = !$var;
  311. print "<tr ".$bc[$var].">";
  312. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  313. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  314. {
  315. print '<td class="nowrap">';
  316. $facturestatic->id=$obj->fk_facture_source;
  317. $facturestatic->ref=$obj->ref;
  318. $facturestatic->type=$obj->type;
  319. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
  320. print '</td>';
  321. }
  322. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  323. {
  324. print '<td class="nowrap">';
  325. $facturestatic->id=$obj->fk_facture_source;
  326. $facturestatic->ref=$obj->ref;
  327. $facturestatic->type=$obj->type;
  328. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
  329. print '</td>';
  330. }
  331. else
  332. {
  333. print '<td>';
  334. print $obj->description;
  335. print '</td>';
  336. }
  337. print '<td class="nowrap">'.$langs->trans("NotConsumed").'</td>';
  338. print '<td align="right">'.price($obj->amount_ht).'</td>';
  339. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  340. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  341. print '<td align="center">';
  342. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  343. print '</td>';
  344. if ($user->rights->societe->creer || $user->rights->facture->creer)
  345. {
  346. print '<td class="nowrap">';
  347. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=split&amp;remid='.$obj->rowid.'">'.img_picto($langs->trans("SplitDiscount"),'split').'</a>';
  348. print ' &nbsp; ';
  349. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;remid='.$obj->rowid.'">'.img_delete($langs->trans("RemoveDiscount")).'</a>';
  350. print '</td>';
  351. }
  352. else print '<td>&nbsp;</td>';
  353. print '</tr>';
  354. if ($_GET["action"]=='split' && GETPOST('remid') == $obj->rowid)
  355. {
  356. $showconfirminfo['rowid']=$obj->rowid;
  357. $showconfirminfo['amount_ttc']=$obj->amount_ttc;
  358. }
  359. $i++;
  360. }
  361. $db->free($resql);
  362. print "</table>";
  363. if (count($showconfirminfo))
  364. {
  365. $amount1=price2num($showconfirminfo['amount_ttc']/2,'MT');
  366. $amount2=($showconfirminfo['amount_ttc']-$amount1);
  367. $formquestion=array(
  368. 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
  369. array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
  370. array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
  371. );
  372. $langs->load("dict");
  373. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'], $langs->trans('SplitDiscount'), $langs->trans('ConfirmSplitDiscount',price($showconfirminfo['amount_ttc']),$langs->transnoentities("Currency".$conf->currency)), 'confirm_split', $formquestion, 0, 0);
  374. }
  375. }
  376. else
  377. {
  378. dol_print_error($db);
  379. }
  380. print '<br>';
  381. /*
  382. * List discount consumed (=liees a une ligne de facture ou facture)
  383. */
  384. // Remises liees a lignes de factures
  385. $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  386. $sql.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
  387. $sql.= " rc.fk_facture_source,";
  388. $sql.= " u.login, u.rowid as user_id,";
  389. $sql.= " f.rowid, f.facnumber,";
  390. $sql.= " fa.facnumber as ref, fa.type as type";
  391. $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
  392. $sql.= " , ".MAIN_DB_PREFIX."user as u";
  393. $sql.= " , ".MAIN_DB_PREFIX."facturedet as fc";
  394. $sql.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  395. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  396. $sql.= " WHERE rc.fk_soc =". $object->id;
  397. $sql.= " AND rc.fk_facture_line = fc.rowid";
  398. $sql.= " AND fc.fk_facture = f.rowid";
  399. $sql.= " AND rc.fk_user = u.rowid";
  400. $sql.= " ORDER BY dc DESC";
  401. //$sql.= " UNION ";
  402. // Remises liees a factures
  403. $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,";
  404. $sql2.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
  405. $sql2.= " rc.fk_facture_source,";
  406. $sql2.= " u.login, u.rowid as user_id,";
  407. $sql2.= " f.rowid, f.facnumber,";
  408. $sql2.= " fa.facnumber as ref, fa.type as type";
  409. $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f";
  410. $sql2.= " , ".MAIN_DB_PREFIX."user as u";
  411. $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
  412. $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
  413. $sql2.= " WHERE rc.fk_soc =". $object->id;
  414. $sql2.= " AND rc.fk_facture = f.rowid";
  415. $sql2.= " AND rc.fk_user = u.rowid";
  416. $sql2.= " ORDER BY dc DESC";
  417. $resql=$db->query($sql);
  418. $resql2=null;
  419. if ($resql) $resql2=$db->query($sql2);
  420. if ($resql2)
  421. {
  422. print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
  423. print '<table class="noborder" width="100%">';
  424. print '<tr class="liste_titre">';
  425. print '<td width="120" align="left">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
  426. print '<td align="left">'.$langs->trans("ReasonDiscount").'</td>';
  427. print '<td width="150" class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
  428. print '<td width="120" align="right">'.$langs->trans("AmountHT").'</td>';
  429. print '<td width="80" align="right">'.$langs->trans("VATRate").'</td>';
  430. print '<td width="120" align="right">'.$langs->trans("AmountTTC").'</td>';
  431. print '<td width="100" align="center">'.$langs->trans("Author").'</td>';
  432. print '<td width="50">&nbsp;</td>';
  433. print '</tr>';
  434. $var = true;
  435. $tab_sqlobj=array();
  436. $tab_sqlobjOrder=array();
  437. $num = $db->num_rows($resql);
  438. for ($i = 0;$i < $num;$i++)
  439. {
  440. $sqlobj = $db->fetch_object($resql);
  441. $tab_sqlobj[] = $sqlobj;
  442. $tab_sqlobjOrder[]=$db->jdate($sqlobj->dc);
  443. }
  444. $db->free($resql);
  445. $num = $db->num_rows($resql2);
  446. for ($i = 0;$i < $num;$i++)
  447. {
  448. $sqlobj = $db->fetch_object($resql2);
  449. $tab_sqlobj[] = $sqlobj;
  450. $tab_sqlobjOrder[]= $db->jdate($sqlobj->dc);
  451. }
  452. $db->free($resql2);
  453. array_multisort($tab_sqlobjOrder,SORT_DESC,$tab_sqlobj);
  454. $num = count($tab_sqlobj);
  455. $i = 0 ;
  456. while ($i < $num )
  457. {
  458. $obj = array_shift($tab_sqlobj);
  459. $var = !$var;
  460. print "<tr ".$bc[$var].">";
  461. print '<td>'.dol_print_date($db->jdate($obj->dc),'dayhour').'</td>';
  462. if (preg_match('/\(CREDIT_NOTE\)/',$obj->description))
  463. {
  464. print '<td class="nowrap">';
  465. $facturestatic->id=$obj->fk_facture_source;
  466. $facturestatic->ref=$obj->ref;
  467. $facturestatic->type=$obj->type;
  468. print preg_replace('/\(CREDIT_NOTE\)/',$langs->trans("CreditNote"),$obj->description).' '.$facturestatic->getNomURl(1);
  469. print '</td>';
  470. }
  471. elseif (preg_match('/\(DEPOSIT\)/',$obj->description))
  472. {
  473. print '<td class="nowrap">';
  474. $facturestatic->id=$obj->fk_facture_source;
  475. $facturestatic->ref=$obj->ref;
  476. $facturestatic->type=$obj->type;
  477. print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
  478. print '</td>';
  479. }
  480. else
  481. {
  482. print '<td>';
  483. print $obj->description;
  484. print '</td>';
  485. }
  486. print '<td align="left" class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
  487. print '<td align="right">'.price($obj->amount_ht).'</td>';
  488. print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
  489. print '<td align="right">'.price($obj->amount_ttc).'</td>';
  490. print '<td align="center">';
  491. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'</a>';
  492. print '</td>';
  493. print '<td>&nbsp;</td>';
  494. print '</tr>';
  495. $i++;
  496. }
  497. print "</table>";
  498. }
  499. else
  500. {
  501. dol_print_error($db);
  502. }
  503. }
  504. llxFooter();
  505. $db->close();