card.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Jean Heimburger <jean@tiaris.info>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/fourn/card.php
  26. * \ingroup fournisseur, facture
  27. * \brief Page for supplier third party card (view, edit)
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  36. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  37. // Load translation files required by page
  38. $langs->loadLangs(array(
  39. 'companies',
  40. 'suppliers',
  41. 'products',
  42. 'bills',
  43. 'orders',
  44. 'commercial',
  45. ));
  46. $action = GETPOST('action','aZ09');
  47. $cancelbutton = GETPOST('cancel','alpha');
  48. // Security check
  49. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  50. if ($user->societe_id) $id=$user->societe_id;
  51. $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid');
  52. $object = new Fournisseur($db);
  53. $extrafields = new ExtraFields($db);
  54. // fetch optionals attributes and labels
  55. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  56. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  57. $hookmanager->initHooks(array('suppliercard','globalcard'));
  58. /*
  59. * Action
  60. */
  61. $parameters=array('id'=>$id);
  62. $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  63. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  64. if (empty($reshook))
  65. {
  66. if ($cancelbutton)
  67. {
  68. $action = "";
  69. }
  70. if ($action == 'setsupplieraccountancycode')
  71. {
  72. $result=$object->fetch($id);
  73. $object->code_compta_fournisseur=$_POST["supplieraccountancycode"];
  74. $result=$object->update($object->id,$user,1,0,1);
  75. if ($result < 0)
  76. {
  77. $mesg=join(',',$object->errors);
  78. }
  79. }
  80. // conditions de reglement
  81. if ($action == 'setconditions' && $user->rights->societe->creer)
  82. {
  83. $object->fetch($id);
  84. $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int'));
  85. if ($result < 0) dol_print_error($db,$object->error);
  86. }
  87. // mode de reglement
  88. if ($action == 'setmode' && $user->rights->societe->creer)
  89. {
  90. $object->fetch($id);
  91. $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int'));
  92. if ($result < 0) dol_print_error($db,$object->error);
  93. }
  94. // update supplier order min amount
  95. if ($action == 'setsupplier_order_min_amount')
  96. {
  97. $object->fetch($id);
  98. $object->supplier_order_min_amount=price2num(GETPOST('supplier_order_min_amount','alpha'));
  99. $result=$object->update($object->id, $user);
  100. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. if ($action == 'update_extras') {
  103. $object->fetch($id);
  104. $object->oldcopy = dol_clone($object);
  105. // Fill array 'array_options' with data from update form
  106. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  107. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none'));
  108. if ($ret < 0) $error++;
  109. if (! $error)
  110. {
  111. $result = $object->insertExtraFields('COMPANY_MODIFY');
  112. if ($result < 0) $error++;
  113. }
  114. if ($error) $action = 'edit_extras';
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. $contactstatic = new Contact($db);
  121. $form = new Form($db);
  122. if ($id > 0 && empty($object->id))
  123. {
  124. // Load data of third party
  125. $res=$object->fetch($id);
  126. if ($object->id <= 0) dol_print_error($db,$object->error);
  127. }
  128. if ($object->id > 0)
  129. {
  130. $title=$langs->trans("ThirdParty")." - ".$langs->trans('Supplier');
  131. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('Supplier');
  132. $help_url='';
  133. llxHeader('',$title, $help_url);
  134. /*
  135. * Show tabs
  136. */
  137. $head = societe_prepare_head($object);
  138. dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), -1, 'company');
  139. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  140. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  141. print '<div class="fichecenter"><div class="fichehalfleft">';
  142. print '<div class="underbanner clearboth"></div>';
  143. print '<table width="100%" class="border">';
  144. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  145. {
  146. print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  147. }
  148. if ($object->fournisseur)
  149. {
  150. print '<tr>';
  151. print '<td class="titlefield">'.$langs->trans("SupplierCode"). '</td><td>';
  152. print $object->code_fournisseur;
  153. if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
  154. print '</td>';
  155. print '</tr>';
  156. $langs->load('compta');
  157. print '<tr>';
  158. print '<td>';
  159. print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  160. print '</td><td>';
  161. print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer);
  162. print '</td>';
  163. print '</tr>';
  164. }
  165. // Assujetti a TVA ou pas
  166. print '<tr>';
  167. print '<td class="titlefield">';
  168. print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
  169. print '</td><td>';
  170. print yn($object->tva_assuj);
  171. print '</td>';
  172. print '</tr>';
  173. // Local Taxes
  174. if ($mysoc->useLocalTax(1))
  175. {
  176. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  177. print yn($object->localtax1_assuj);
  178. print '</td></tr>';
  179. }
  180. if ($mysoc->useLocalTax(2))
  181. {
  182. print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  183. print yn($object->localtax2_assuj);
  184. print '</td></tr>';
  185. }
  186. // TVA Intra
  187. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  188. print $object->tva_intra;
  189. print '</td></tr>';
  190. // Conditions de reglement par defaut
  191. $langs->load('bills');
  192. $form = new Form($db);
  193. print '<tr><td>';
  194. print '<table width="100%" class="nobordernopadding"><tr><td>';
  195. print $langs->trans('PaymentConditions');
  196. print '<td>';
  197. if (($action != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
  198. print '</tr></table>';
  199. print '</td><td>';
  200. if ($action == 'editconditions')
  201. {
  202. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'cond_reglement_supplier_id',-1,1);
  203. }
  204. else
  205. {
  206. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'none');
  207. }
  208. print "</td>";
  209. print '</tr>';
  210. // Mode de reglement par defaut
  211. print '<tr><td class="nowrap">';
  212. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  213. print $langs->trans('PaymentMode');
  214. print '<td>';
  215. if (($action != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  216. print '</tr></table>';
  217. print '</td><td>';
  218. if ($action == 'editmode')
  219. {
  220. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'mode_reglement_supplier_id', 'DBIT', 1, 1);
  221. }
  222. else
  223. {
  224. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'none');
  225. }
  226. print "</td>";
  227. print '</tr>';
  228. // Relative discounts (Discounts-Drawbacks-Rebates)
  229. print '<tr><td class="nowrap">';
  230. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  231. print $langs->trans("CustomerRelativeDiscountShort");
  232. print '<td><td align="right">';
  233. if ($user->rights->societe->creer && !$user->societe_id > 0)
  234. {
  235. print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  236. }
  237. print '</td></tr></table>';
  238. print '</td><td>'.($object->remise_supplier_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_supplier_percent.'%</a>':'').'</td>';
  239. print '</tr>';
  240. // Absolute discounts (Discounts-Drawbacks-Rebates)
  241. print '<tr><td class="nowrap">';
  242. print '<table width="100%" class="nobordernopadding">';
  243. print '<tr><td class="nowrap">';
  244. print $langs->trans("CustomerAbsoluteDiscountShort");
  245. print '<td><td align="right">';
  246. if ($user->rights->societe->creer && !$user->societe_id > 0)
  247. {
  248. print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
  249. }
  250. print '</td></tr></table>';
  251. print '</td>';
  252. print '<td>';
  253. $amount_discount=$object->getAvailableDiscounts('', '', 0, 1);
  254. if ($amount_discount < 0) dol_print_error($db,$object->error);
  255. if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount,1,$langs,1,-1,-1,$conf->currency).'</a>';
  256. //else print $langs->trans("DiscountNone");
  257. print '</td>';
  258. print '</tr>';
  259. if (! empty($conf->fournisseur->enabled) && ! empty($conf->global->ORDER_MANAGE_MIN_AMOUNT))
  260. {
  261. print '<tr class="nowrap">';
  262. print '<td>';
  263. print $form->editfieldkey("OrderMinAmount",'supplier_order_min_amount',$object->supplier_order_min_amount,$object,$user->rights->societe->creer);
  264. print '</td><td>';
  265. $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
  266. print $form->editfieldval("OrderMinAmount",'supplier_order_min_amount',$object->supplier_order_min_amount,$object,$user->rights->societe->creer,$limit_field_type,($object->supplier_order_min_amount != '' ? price($object->supplier_order_min_amount) : ''));
  267. print '</td>';
  268. print '</tr>';
  269. }
  270. // Categories
  271. if (! empty($conf->categorie->enabled))
  272. {
  273. $langs->load("categories");
  274. print '<tr><td>' . $langs->trans("SuppliersCategoriesShort") . '</td>';
  275. print '<td>';
  276. print $form->showCategories($object->id, 'supplier', 1);
  277. print "</td></tr>";
  278. }
  279. // Other attributes
  280. $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  281. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  282. // Module Adherent
  283. if (! empty($conf->adherent->enabled))
  284. {
  285. $langs->load("members");
  286. $langs->load("users");
  287. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  288. print '<td>';
  289. $adh=new Adherent($db);
  290. $result=$adh->fetch('','',$object->id);
  291. if ($result > 0)
  292. {
  293. $adh->ref=$adh->getFullName($langs);
  294. print $adh->getNomUrl(1);
  295. }
  296. else
  297. {
  298. print $langs->trans("ThirdpartyNotLinkedToMember");
  299. }
  300. print '</td>';
  301. print "</tr>\n";
  302. }
  303. print '</table>';
  304. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  305. $boxstat = '';
  306. // Nbre max d'elements des petites listes
  307. $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  308. print '<div class="underbanner clearboth"></div>';
  309. // Lien recap
  310. $boxstat.='<div class="box">';
  311. $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
  312. $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
  313. if ($conf->supplier_proposal->enabled)
  314. {
  315. // Box proposals
  316. $tmp = $object->getOutstandingProposals('supplier');
  317. $outstandingOpened=$tmp['opened'];
  318. $outstandingTotal=$tmp['total_ht'];
  319. $outstandingTotalIncTax=$tmp['total_ttc'];
  320. $text=$langs->trans("OverAllSupplierProposals");
  321. $link=DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id;
  322. $icon='bill';
  323. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  324. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  325. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  326. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  327. $boxstat.='</div>';
  328. if ($link) $boxstat.='</a>';
  329. }
  330. if ($conf->fournisseur->enabled)
  331. {
  332. // Box proposals
  333. $tmp = $object->getOutstandingOrders('supplier');
  334. $outstandingOpened=$tmp['opened'];
  335. $outstandingTotal=$tmp['total_ht'];
  336. $outstandingTotalIncTax=$tmp['total_ttc'];
  337. $text=$langs->trans("OverAllOrders");
  338. $link=DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id;
  339. $icon='bill';
  340. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  341. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  342. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  343. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  344. $boxstat.='</div>';
  345. if ($link) $boxstat.='</a>';
  346. }
  347. if ($conf->fournisseur->enabled)
  348. {
  349. $tmp = $object->getOutstandingBills('supplier');
  350. $outstandingOpened=$tmp['opened'];
  351. $outstandingTotal=$tmp['total_ht'];
  352. $outstandingTotalIncTax=$tmp['total_ttc'];
  353. $text=$langs->trans("OverAllInvoices");
  354. $link=DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id;
  355. $icon='bill';
  356. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  357. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  358. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  359. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  360. $boxstat.='</div>';
  361. if ($link) $boxstat.='</a>';
  362. // Box outstanding bill
  363. $text=$langs->trans("CurrentOutstandingBill");
  364. $link=DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
  365. $icon='bill';
  366. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  367. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  368. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  369. $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  370. $boxstat.='</div>';
  371. if ($link) $boxstat.='</a>';
  372. }
  373. $boxstat.='</td></tr>';
  374. $boxstat.='</table>';
  375. $boxstat.='</div>';
  376. print $boxstat;
  377. $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  378. // Lien recap
  379. /*
  380. print '<table class="noborder" width="100%">';
  381. print '<tr class="liste_titre">';
  382. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
  383. print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
  384. print '</tr>';
  385. print '</table>';
  386. print '<br>';
  387. */
  388. /*
  389. * List of products
  390. */
  391. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled))
  392. {
  393. $langs->load("products");
  394. //Query from product/liste.php
  395. $sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.entity,';
  396. $sql.= ' pfp.tms, pfp.ref_fourn as supplier_ref, pfp.price, pfp.quantity, pfp.unitprice';
  397. $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
  398. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product";
  399. $sql.= ' WHERE p.entity IN ('.getEntity('product').')';
  400. $sql.= ' AND pfp.fk_soc = '.$object->id;
  401. $sql .= $db->order('pfp.tms', 'desc');
  402. $sql.= $db->plimit($MAXLIST);
  403. $query = $db->query($sql);
  404. if (! $query) dol_print_error($db);
  405. $num = $db->num_rows($query);
  406. print '<table class="noborder" width="100%">';
  407. print '<tr class="liste_titre'.(($num == 0) ? ' nobottom':'').'">';
  408. print '<td colspan="3">'.$langs->trans("ProductsAndServices").'</td><td align="right">';
  409. print '<a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/product/list.php?fourn_id='.$object->id.'">'.$langs->trans("AllProductReferencesOfSupplier").' <span class="badge">'.$object->nbOfProductRefs().'</span>';
  410. print '</a></td></tr>';
  411. $return = array();
  412. if ($num > 0)
  413. {
  414. $productstatic = new Product($db);
  415. while ($objp = $db->fetch_object($query))
  416. {
  417. $productstatic->id = $objp->rowid;
  418. $productstatic->ref = $objp->ref;
  419. $productstatic->label = $objp->label;
  420. $productstatic->type = $objp->fk_product_type;
  421. $productstatic->entity = $objp->entity;
  422. print '<tr class="oddeven">';
  423. print '<td class="nowrap">';
  424. print $productstatic->getNomUrl(1);
  425. print '</td>';
  426. print '<td>';
  427. print $objp->supplier_ref;
  428. print '</td>';
  429. print '<td class="maxwidthonsmartphone">';
  430. print dol_trunc(dol_htmlentities($objp->label), 30);
  431. print '</td>';
  432. //print '<td align="right" class="nowrap">'.dol_print_date($objp->tms, 'day').'</td>';
  433. print '<td align="right">';
  434. //print (isset($objp->unitprice) ? price($objp->unitprice) : '');
  435. if (isset($objp->price))
  436. {
  437. print price($objp->price);
  438. if ($objp->quantity > 1)
  439. {
  440. print ' / ';
  441. print $objp->quantity;
  442. }
  443. }
  444. print '</td>';
  445. print '</tr>';
  446. }
  447. }
  448. print '</table>';
  449. }
  450. /*
  451. * Latest supplier proposal
  452. */
  453. $proposalstatic = new SupplierProposal($db);
  454. if ($user->rights->supplier_proposal->lire)
  455. {
  456. $sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total as total_ttc";
  457. $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p ";
  458. $sql.= " WHERE p.fk_soc =".$object->id;
  459. $sql.= " AND p.entity IN (".getEntity('supplier_proposal').")";
  460. $sql.= " ORDER BY p.date_valid DESC";
  461. $sql.= " ".$db->plimit($MAXLIST);
  462. $resql=$db->query($sql);
  463. if ($resql)
  464. {
  465. $i = 0 ;
  466. $num = $db->num_rows($resql);
  467. if ($num > 0)
  468. {
  469. print '<table class="noborder" width="100%">';
  470. print '<tr class="liste_titre">';
  471. print '<td colspan="3">';
  472. print '<table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastSupplierProposals",($num<$MAXLIST?"":$MAXLIST)).'</td>';
  473. print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id.'">'.$langs->trans("AllPriceRequests").' <span class="badge">'.$num.'</span></td>';
  474. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/supplier_proposal/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  475. print '</tr></table>';
  476. print '</td></tr>';
  477. }
  478. while ($i < $num && $i <= $MAXLIST)
  479. {
  480. $obj = $db->fetch_object($resql);
  481. print '<tr class="oddeven">';
  482. print '<td class="nowrap">';
  483. $proposalstatic->id = $obj->rowid;
  484. $proposalstatic->ref = $obj->ref;
  485. $proposalstatic->total_ht = $obj->total_ht;
  486. $proposalstatic->total_tva = $obj->total_tva;
  487. $proposalstatic->total_ttc = $obj->total_ttc;
  488. print $proposalstatic->getNomUrl(1);
  489. print '</td>';
  490. print '<td align="center" width="80">';
  491. if ($obj->dc)
  492. {
  493. print dol_print_date($db->jdate($obj->dc),'day');
  494. }
  495. else
  496. {
  497. print "-";
  498. }
  499. print '</td>';
  500. print '<td align="right" class="nowrap">'.$proposalstatic->LibStatut($obj->fk_statut,5).'</td>';
  501. print '</tr>';
  502. $i++;
  503. }
  504. $db->free($resql);
  505. if ($num >0) print "</table>";
  506. }
  507. else
  508. {
  509. dol_print_error($db);
  510. }
  511. }
  512. /*
  513. * Latest supplier orders
  514. */
  515. $orderstatic = new CommandeFournisseur($db);
  516. if ($user->rights->fournisseur->commande->lire)
  517. {
  518. // TODO move to DAO class
  519. // Check if there are supplier orders billable
  520. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
  521. $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
  522. $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  523. $sql2.= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
  524. $sql2.= ' WHERE c.fk_soc = s.rowid';
  525. $sql2.= " AND c.entity IN (".getEntity('commande_fournisseur').")";
  526. $sql2.= ' AND s.rowid = '.$object->id;
  527. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  528. $sql2.= " AND c.fk_statut IN (5)";
  529. $sql2.= " AND c.billed = 0";
  530. // Find order that are not already invoiced
  531. // just need to check received status because we have the billed status now
  532. //$sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
  533. $resql2=$db->query($sql2);
  534. if ($resql2) {
  535. $orders2invoice = $db->num_rows($resql2);
  536. $db->free($resql2);
  537. } else {
  538. setEventMessages($db->lasterror(), null, 'errors');
  539. }
  540. // TODO move to DAO class
  541. $sql = "SELECT count(p.rowid) as total";
  542. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
  543. $sql.= " WHERE p.fk_soc =".$object->id;
  544. $sql.= " AND p.entity IN (".getEntity('commande_fournisseur').")";
  545. $resql=$db->query($sql);
  546. if ($resql)
  547. {
  548. $object_count = $db->fetch_object($resql);
  549. $num = $object_count->total;
  550. }
  551. $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total_ttc";
  552. $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
  553. $sql.= " WHERE p.fk_soc =".$object->id;
  554. $sql.= " AND p.entity IN (".getEntity('commande_fournisseur').")";
  555. $sql.= " ORDER BY p.date_commande DESC";
  556. $sql.= " ".$db->plimit($MAXLIST);
  557. $resql=$db->query($sql);
  558. if ($resql)
  559. {
  560. $i = 0 ;
  561. if ($num > 0)
  562. {
  563. print '<table class="noborder" width="100%">';
  564. print '<tr class="liste_titre">';
  565. print '<td colspan="3">';
  566. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierOrders",($num<$MAXLIST?"":$MAXLIST)).'</td>';
  567. print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></td>';
  568. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  569. print '</tr></table>';
  570. print '</td></tr>';
  571. }
  572. while ($i < $num && $i < $MAXLIST)
  573. {
  574. $obj = $db->fetch_object($resql);
  575. print '<tr class="oddeven">';
  576. print '<td class="nowrap">';
  577. $orderstatic->id = $obj->rowid;
  578. $orderstatic->ref = $obj->ref;
  579. $orderstatic->total_ht = $obj->total_ht;
  580. $orderstatic->total_tva = $obj->total_tva;
  581. $orderstatic->total_ttc = $obj->total_ttc;
  582. print $orderstatic->getNomUrl(1);
  583. print '</td>';
  584. print '<td align="center" width="80">';
  585. if ($obj->dc)
  586. {
  587. print dol_print_date($db->jdate($obj->dc),'day');
  588. }
  589. else
  590. {
  591. print "-";
  592. }
  593. print '</td>';
  594. print '<td align="right" class="nowrap">'.$orderstatic->LibStatut($obj->fk_statut,5).'</td>';
  595. print '</tr>';
  596. $i++;
  597. }
  598. $db->free($resql);
  599. if ($num >0) print "</table>";
  600. }
  601. else
  602. {
  603. dol_print_error($db);
  604. }
  605. }
  606. /*
  607. * Latest supplier invoices
  608. */
  609. $langs->load('bills');
  610. $facturestatic = new FactureFournisseur($db);
  611. if ($user->rights->fournisseur->facture->lire)
  612. {
  613. // TODO move to DAO class
  614. $sql = 'SELECT f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef as df, f.total_ht, f.total_tva, f.total_ttc as amount,f.paye,';
  615. $sql.= ' SUM(pf.amount) as am';
  616. $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
  617. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
  618. $sql.= ' WHERE f.fk_soc = '.$object->id;
  619. $sql.= " AND f.entity IN (".getEntity('facture_fourn').")";
  620. $sql.= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye';
  621. $sql.= ' ORDER BY f.datef DESC';
  622. $resql=$db->query($sql);
  623. if ($resql)
  624. {
  625. $i = 0 ;
  626. $num = $db->num_rows($resql);
  627. if ($num > 0)
  628. {
  629. print '<table class="noborder" width="100%">';
  630. print '<tr class="liste_titre">';
  631. print '<td colspan="4">';
  632. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id.'">'.$langs->trans('AllBills').' <span class="badge">'.$num.'</span></td>';
  633. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  634. print '</tr></table>';
  635. print '</td></tr>';
  636. }
  637. while ($i < min($num,$MAXLIST))
  638. {
  639. $obj = $db->fetch_object($resql);
  640. print '<tr class="oddeven">';
  641. print '<td>';
  642. print '<a href="facture/card.php?facid='.$obj->rowid.'">';
  643. $facturestatic->id=$obj->rowid;
  644. $facturestatic->ref=($obj->ref?$obj->ref:$obj->rowid);
  645. $facturestatic->ref_supplier = $obj->ref_supplier;
  646. $facturestatic->libelle = $obj->libelle;
  647. $facturestatic->total_ht = $obj->total_ht;
  648. $facturestatic->total_tva = $obj->total_tva;
  649. $facturestatic->total_ttc = $obj->total_ttc;
  650. print $facturestatic->getNomUrl(1);
  651. print $obj->ref_supplier?' - '.$obj->ref_supplier:'';
  652. print ($obj->libelle?' - ':'').dol_trunc($obj->libelle,14);
  653. print '</td>';
  654. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->df),'day').'</td>';
  655. print '<td align="right" class="nowrap">'.price($obj->amount).'</td>';
  656. print '<td align="right" class="nowrap">';
  657. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$obj->am);
  658. print '</td>';
  659. print '</tr>';
  660. $i++;
  661. }
  662. $db->free($resql);
  663. if ($num > 0) print '</table>';
  664. }
  665. else
  666. {
  667. dol_print_error($db);
  668. }
  669. }
  670. print '</div></div></div>';
  671. print '<div style="clear:both"></div>';
  672. dol_fiche_end();
  673. /*
  674. * Barre d'actions
  675. */
  676. print '<div class="tabsAction">';
  677. $parameters = array();
  678. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  679. // modified by hook
  680. if (empty($reshook))
  681. {
  682. if ($object->status != 1)
  683. {
  684. print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  685. }
  686. if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer)
  687. {
  688. $langs->load("supplier_proposal");
  689. if ($object->status == 1)
  690. {
  691. print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddSupplierProposal").'</a>';
  692. }
  693. else
  694. {
  695. print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddSupplierProposal").'</a>';
  696. }
  697. }
  698. if ($user->rights->fournisseur->commande->creer)
  699. {
  700. $langs->load("orders");
  701. if ($object->status == 1)
  702. {
  703. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
  704. }
  705. else
  706. {
  707. print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddOrder").'</a>';
  708. }
  709. }
  710. if ($user->rights->fournisseur->facture->creer)
  711. {
  712. $langs->load("bills");
  713. if ($object->status == 1)
  714. {
  715. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
  716. }
  717. else
  718. {
  719. print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddBill").'</a>';
  720. }
  721. }
  722. if ($user->rights->fournisseur->facture->creer)
  723. {
  724. if (! empty($orders2invoice) && $orders2invoice > 0)
  725. {
  726. if ($object->status == 1)
  727. {
  728. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  729. }
  730. else
  731. {
  732. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  733. }
  734. }
  735. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  736. }
  737. // Add action
  738. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
  739. {
  740. if ($user->rights->agenda->myactions->create)
  741. {
  742. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
  743. }
  744. else
  745. {
  746. print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
  747. }
  748. }
  749. }
  750. print '</div>';
  751. if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
  752. {
  753. print '<br>';
  754. // List of contacts
  755. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  756. }
  757. // Addresses list
  758. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  759. {
  760. $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  761. }
  762. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  763. {
  764. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  765. // List of todo actions
  766. show_actions_todo($conf,$langs,$db,$object);
  767. // List of done actions
  768. show_actions_done($conf,$langs,$db,$object);
  769. }
  770. }
  771. else
  772. {
  773. dol_print_error($db);
  774. }
  775. // End of page
  776. llxFooter();
  777. $db->close();