card.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  8. * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  10. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/comm/card.php
  27. * \ingroup commercial compta
  28. * \brief Page to show customer card of a third party
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  37. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  38. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  39. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  40. if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  41. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  42. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  43. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  44. $langs->load("companies");
  45. $langs->load('banks');
  46. if (! empty($conf->contrat->enabled)) $langs->load("contracts");
  47. if (! empty($conf->commande->enabled)) $langs->load("orders");
  48. if (! empty($conf->expedition->enabled)) $langs->load("sendings");
  49. if (! empty($conf->facture->enabled)) $langs->load("bills");
  50. if (! empty($conf->projet->enabled)) $langs->load("projects");
  51. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  52. if (! empty($conf->notification->enabled)) $langs->load("mails");
  53. // Security check
  54. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  55. if ($user->societe_id > 0) $id=$user->societe_id;
  56. $result = restrictedArea($user,'societe',$id,'&societe');
  57. $action = GETPOST('action','aZ09');
  58. $mode = GETPOST("mode");
  59. $sortfield = GETPOST("sortfield",'alpha');
  60. $sortorder = GETPOST("sortorder",'alpha');
  61. $page = GETPOST("page",'int');
  62. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  63. $offset = $conf->liste_limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. if (! $sortorder) $sortorder="ASC";
  67. if (! $sortfield) $sortfield="nom";
  68. $cancelbutton = GETPOST('cancel');
  69. $object = new Client($db);
  70. $extrafields = new ExtraFields($db);
  71. // fetch optionals attributes and labels
  72. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  73. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  74. $hookmanager->initHooks(array('commcard','globalcard'));
  75. /*
  76. * Actions
  77. */
  78. $parameters = array('id' => $id, 'socid' => $id);
  79. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
  80. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  81. if (empty($reshook))
  82. {
  83. if ($cancelbutton)
  84. {
  85. $action="";
  86. }
  87. // set accountancy code
  88. if ($action == 'setcustomeraccountancycode')
  89. {
  90. $result=$object->fetch($id);
  91. $object->code_compta=$_POST["customeraccountancycode"];
  92. $result=$object->update($object->id,$user,1,1,0);
  93. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  94. }
  95. // conditions de reglement
  96. if ($action == 'setconditions' && $user->rights->societe->creer)
  97. {
  98. $object->fetch($id);
  99. $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  100. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. // mode de reglement
  103. if ($action == 'setmode' && $user->rights->societe->creer)
  104. {
  105. $object->fetch($id);
  106. $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
  107. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. // Bank account
  110. if ($action == 'setbankaccount' && $user->rights->societe->creer)
  111. {
  112. $object->fetch($id);
  113. $result=$object->setBankAccount(GETPOST('fk_account','int'));
  114. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  115. }
  116. // customer preferred shipping method
  117. if ($action == 'setshippingmethod' && $user->rights->societe->creer)
  118. {
  119. $object->fetch($id);
  120. $result = $object->setShippingMethod(GETPOST('shipping_method_id','int'));
  121. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  122. }
  123. // assujetissement a la TVA
  124. if ($action == 'setassujtva' && $user->rights->societe->creer)
  125. {
  126. $object->fetch($id);
  127. $object->tva_assuj=$_POST['assujtva_value'];
  128. $result=$object->update($object->id);
  129. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  130. }
  131. // set prospect level
  132. if ($action == 'setprospectlevel' && $user->rights->societe->creer)
  133. {
  134. $object->fetch($id);
  135. $object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
  136. $result=$object->update($object->id, $user);
  137. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  138. }
  139. // set communication status
  140. if ($action == 'setstcomm')
  141. {
  142. $object->fetch($id);
  143. $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm');
  144. $result=$object->update($object->id, $user);
  145. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  146. }
  147. // update outstandng limit
  148. if ($action == 'setoutstanding_limit')
  149. {
  150. $object->fetch($id);
  151. $object->outstanding_limit=GETPOST('outstanding_limit');
  152. $result=$object->update($object->id, $user);
  153. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  154. }
  155. }
  156. /*
  157. * View
  158. */
  159. $contactstatic = new Contact($db);
  160. $userstatic=new User($db);
  161. $form = new Form($db);
  162. $formcompany=new FormCompany($db);
  163. if ($id > 0 && empty($object->id))
  164. {
  165. // Load data of third party
  166. $res=$object->fetch($id);
  167. if ($object->id <= 0) dol_print_error($db,$object->error);
  168. }
  169. $title=$langs->trans("CustomerCard");
  170. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name;
  171. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  172. llxHeader('',$title,$help_url);
  173. if ($id > 0)
  174. {
  175. $head = societe_prepare_head($object);
  176. dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
  177. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
  178. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  179. print '<div class="fichecenter"><div class="fichehalfleft">';
  180. print '<div class="underbanner clearboth"></div>';
  181. print '<table class="border" width="100%">';
  182. // Prospect/Customer
  183. print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
  184. print $object->getLibCustProspStatut();
  185. print '</td></tr>';
  186. // Prefix
  187. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  188. {
  189. print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
  190. print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
  191. print '</td></tr>';
  192. }
  193. if ($object->client)
  194. {
  195. $langs->load("compta");
  196. print '<tr><td>';
  197. print $langs->trans('CustomerCode').'</td><td>';
  198. print $object->code_client;
  199. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  200. print '</td></tr>';
  201. print '<tr>';
  202. print '<td>';
  203. print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  204. print '</td><td>';
  205. print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  206. print '</td>';
  207. print '</tr>';
  208. }
  209. // Assujeti a TVA ou pas
  210. print '<tr>';
  211. print '<td class="nowrap">'.$langs->trans('VATIsUsed').'</td><td>';
  212. print yn($object->tva_assuj);
  213. print '</td>';
  214. print '</tr>';
  215. // Local Taxes
  216. if ($mysoc->useLocalTax(1))
  217. {
  218. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  219. print yn($object->localtax1_assuj);
  220. print '</td></tr>';
  221. }
  222. if ($mysoc->useLocalTax(2))
  223. {
  224. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  225. print yn($object->localtax2_assuj);
  226. print '</td></tr>';
  227. }
  228. // TVA Intra
  229. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  230. print $object->tva_intra;
  231. print '</td></tr>';
  232. // Conditions de reglement par defaut
  233. $langs->load('bills');
  234. print '<tr><td>';
  235. print '<table width="100%" class="nobordernopadding"><tr><td>';
  236. print $langs->trans('PaymentConditions');
  237. print '<td>';
  238. 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>';
  239. print '</tr></table>';
  240. print '</td><td>';
  241. if ($action == 'editconditions')
  242. {
  243. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id',1);
  244. }
  245. else
  246. {
  247. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
  248. }
  249. print "</td>";
  250. print '</tr>';
  251. // Mode de reglement par defaut
  252. print '<tr><td class="nowrap">';
  253. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  254. print $langs->trans('PaymentMode');
  255. print '<td>';
  256. 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>';
  257. print '</tr></table>';
  258. print '</td><td>';
  259. if ($action == 'editmode')
  260. {
  261. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
  262. }
  263. else
  264. {
  265. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'none');
  266. }
  267. print "</td>";
  268. print '</tr>';
  269. // Compte bancaire par défaut
  270. print '<tr><td class="nowrap">';
  271. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  272. print $langs->trans('PaymentBankAccount');
  273. print '<td>';
  274. if (($action != 'editbankaccount') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  275. print '</tr></table>';
  276. print '</td><td>';
  277. if ($action == 'editbankaccount')
  278. {
  279. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1);
  280. }
  281. else
  282. {
  283. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none');
  284. }
  285. print "</td>";
  286. print '</tr>';
  287. // Relative discounts (Discounts-Drawbacks-Rebates)
  288. print '<tr><td class="nowrap">';
  289. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  290. print $langs->trans("CustomerRelativeDiscountShort");
  291. print '<td><td align="right">';
  292. if ($user->rights->societe->creer && !$user->societe_id > 0)
  293. {
  294. print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  295. }
  296. print '</td></tr></table>';
  297. print '</td><td>'.($object->remise_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>':'').'</td>';
  298. print '</tr>';
  299. // Absolute discounts (Discounts-Drawbacks-Rebates)
  300. print '<tr><td class="nowrap">';
  301. print '<table width="100%" class="nobordernopadding">';
  302. print '<tr><td class="nowrap">';
  303. print $langs->trans("CustomerAbsoluteDiscountShort");
  304. print '<td><td align="right">';
  305. if ($user->rights->societe->creer && !$user->societe_id > 0)
  306. {
  307. 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>';
  308. }
  309. print '</td></tr></table>';
  310. print '</td>';
  311. print '<td>';
  312. $amount_discount=$object->getAvailableDiscounts();
  313. if ($amount_discount < 0) dol_print_error($db,$object->error);
  314. 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>';
  315. //else print $langs->trans("DiscountNone");
  316. print '</td>';
  317. print '</tr>';
  318. // Max outstanding bill
  319. if ($object->client)
  320. {
  321. print '<tr class="nowrap">';
  322. print '<td>';
  323. print $form->editfieldkey("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer);
  324. print '</td><td>';
  325. $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
  326. print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
  327. //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
  328. print '</td>';
  329. print '</tr>';
  330. }
  331. // Multiprice level
  332. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  333. {
  334. print '<tr><td class="nowrap">';
  335. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  336. print $langs->trans("PriceLevel");
  337. print '<td><td align="right">';
  338. if ($user->rights->societe->creer)
  339. {
  340. print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  341. }
  342. print '</td></tr></table>';
  343. print '</td><td>';
  344. print $object->price_level;
  345. $keyforlabel='PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
  346. if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel);
  347. print "</td>";
  348. print '</tr>';
  349. }
  350. // Preferred shipping Method
  351. if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
  352. print '<tr><td class="nowrap">';
  353. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  354. print $langs->trans('SendingMethod');
  355. print '<td>';
  356. if (($action != 'editshipping') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  357. print '</tr></table>';
  358. print '</td><td>';
  359. if ($action == 'editshipping')
  360. {
  361. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'shipping_method_id');
  362. }
  363. else
  364. {
  365. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'none');
  366. }
  367. print "</td>";
  368. print '</tr>';
  369. }
  370. // Categories
  371. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  372. $langs->load("categories");
  373. print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
  374. print '<td>';
  375. print $form->showCategories( $object->id, 'customer', 1 );
  376. print "</td></tr>";
  377. }
  378. // Other attributes
  379. $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  380. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  381. print $hookmanager->resPrint;
  382. if (empty($reshook) && ! empty($extrafields->attribute_label))
  383. {
  384. print $object->showOptionals($extrafields);
  385. }
  386. // Sales representative
  387. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  388. // Module Adherent
  389. if (! empty($conf->adherent->enabled))
  390. {
  391. $langs->load("members");
  392. $langs->load("users");
  393. print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  394. print '<td>';
  395. $adh=new Adherent($db);
  396. $result=$adh->fetch('','',$object->id);
  397. if ($result > 0)
  398. {
  399. $adh->ref=$adh->getFullName($langs);
  400. print $adh->getNomUrl(1);
  401. }
  402. else
  403. {
  404. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  405. }
  406. print '</td>';
  407. print "</tr>\n";
  408. }
  409. print "</table>";
  410. if ($object->client == 2 || $object->client == 3)
  411. {
  412. print '<br>';
  413. print '<div class="underbanner clearboth"></div>';
  414. print '<table class="border" width="100%">';
  415. // Level of prospect
  416. print '<tr><td class="titlefield nowrap">';
  417. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  418. print $langs->trans('ProspectLevel');
  419. print '<td>';
  420. if ($action != 'editlevel' && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&amp;socid='.$object->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
  421. print '</tr></table>';
  422. print '</td><td>';
  423. if ($action == 'editlevel')
  424. {
  425. $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
  426. }
  427. else
  428. {
  429. print $object->getLibProspLevel();
  430. }
  431. print "</td>";
  432. print '</tr>';
  433. // Status
  434. $object->loadCacheOfProspStatus();
  435. print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
  436. print ' &nbsp; &nbsp; ';
  437. print '<div class="floatright">';
  438. foreach($object->cacheprospectstatus as $key => $val)
  439. {
  440. $titlealt='default';
  441. if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
  442. if ($object->stcomm_id != $val['id']) print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&stcomm='.$val['code'].'&action=setstcomm">'.img_action($titlealt,$val['code']).'</a>';
  443. }
  444. print '</div></td></tr>';
  445. print "</table>";
  446. }
  447. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  448. $boxstat = '';
  449. // Nbre max d'elements des petites listes
  450. $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  451. // Lien recap
  452. $boxstat.='<div class="box">';
  453. $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable boxtablenobottom" width="100%">';
  454. $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
  455. if ($conf->propal->enabled)
  456. {
  457. // Box proposals
  458. $tmp = $object->getOutstandingProposals();
  459. $outstandingOpened=$tmp['opened'];
  460. $outstandingTotal=$tmp['total_ht'];
  461. $outstandingTotalIncTax=$tmp['total_ttc'];
  462. $text=$langs->trans("OverAllProposals");
  463. $link='';
  464. $icon='bill';
  465. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  466. $boxstat.='<div class="boxstats">';
  467. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  468. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  469. $boxstat.='</div>';
  470. if ($link) $boxstat.='</a>';
  471. }
  472. if ($conf->commande->enabled)
  473. {
  474. // Box proposals
  475. $tmp = $object->getOutstandingOrders();
  476. $outstandingOpened=$tmp['opened'];
  477. $outstandingTotal=$tmp['total_ht'];
  478. $outstandingTotalIncTax=$tmp['total_ttc'];
  479. $text=$langs->trans("OverAllOrders");
  480. $link='';
  481. $icon='bill';
  482. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  483. $boxstat.='<div class="boxstats">';
  484. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  485. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  486. $boxstat.='</div>';
  487. if ($link) $boxstat.='</a>';
  488. }
  489. if ($conf->facture->enabled)
  490. {
  491. $tmp = $object->getOutstandingBills();
  492. $outstandingOpened=$tmp['opened'];
  493. $outstandingTotal=$tmp['total_ht'];
  494. $outstandingTotalIncTax=$tmp['total_ttc'];
  495. $text=$langs->trans("OverAllInvoices");
  496. $link='';
  497. $icon='bill';
  498. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  499. $boxstat.='<div class="boxstats">';
  500. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  501. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  502. $boxstat.='</div>';
  503. if ($link) $boxstat.='</a>';
  504. // Box outstanding bill
  505. $warn = '';
  506. if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
  507. {
  508. $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
  509. }
  510. $text=$langs->trans("CurrentOutstandingBill");
  511. $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
  512. $icon='bill';
  513. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  514. $boxstat.='<div class="boxstats">';
  515. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  516. $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  517. $boxstat.='</div>';
  518. if ($link) $boxstat.='</a>';
  519. }
  520. $boxstat.='</td></tr>';
  521. $boxstat.='</table>';
  522. $boxstat.='</div>';
  523. print $boxstat;
  524. $now=dol_now();
  525. /*
  526. * Last proposals
  527. */
  528. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  529. {
  530. $propal_static = new Propal($db);
  531. $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
  532. $sql.= ", p.tva as total_tva";
  533. $sql.= ", p.total as total_ttc";
  534. $sql.= ", p.ref, p.ref_client, p.remise";
  535. $sql.= ", p.datep as dp, p.fin_validite as datelimite";
  536. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
  537. $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
  538. $sql.= " AND s.rowid = ".$object->id;
  539. $sql.= " AND p.entity = ".$conf->entity;
  540. $sql.= " ORDER BY p.datep DESC";
  541. $resql=$db->query($sql);
  542. if ($resql)
  543. {
  544. $var=true;
  545. $num = $db->num_rows($resql);
  546. if ($num > 0)
  547. {
  548. print '<table class="noborder" width="100%">';
  549. print '<tr class="liste_titre">';
  550. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id.'">'.$langs->trans("AllPropals").' <span class="badge">'.$num.'</span></a></td>';
  551. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  552. print '</tr></table></td>';
  553. print '</tr>';
  554. }
  555. $i = 0;
  556. while ($i < $num && $i < $MAXLIST)
  557. {
  558. $objp = $db->fetch_object($resql);
  559. print '<tr class="oddeven">';
  560. print '<td class="nowrap">';
  561. $propal_static->id = $objp->propalid;
  562. $propal_static->ref = $objp->ref;
  563. $propal_static->ref_client = $objp->ref_client;
  564. $propal_static->total_ht = $objp->total_ht;
  565. $propal_static->total_tva = $objp->total_tva;
  566. $propal_static->total_ttc = $objp->total_ttc;
  567. print $propal_static->getNomUrl(1);
  568. if ( ($db->jdate($objp->datelimite) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 ) {
  569. print " ".img_warning();
  570. }
  571. print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  572. print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  573. print '<td align="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
  574. $i++;
  575. }
  576. $db->free($resql);
  577. if ($num > 0) print "</table>";
  578. }
  579. else
  580. {
  581. dol_print_error($db);
  582. }
  583. }
  584. /*
  585. * Last orders
  586. */
  587. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  588. {
  589. $commande_static=new Commande($db);
  590. $sql = "SELECT s.nom, s.rowid";
  591. $sql.= ", c.rowid as cid, c.total_ht";
  592. $sql.= ", c.tva as total_tva";
  593. $sql.= ", c.total_ttc";
  594. $sql.= ", c.ref, c.ref_client, c.fk_statut, c.facture";
  595. $sql.= ", c.date_commande as dc";
  596. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
  597. $sql.= " WHERE c.fk_soc = s.rowid ";
  598. $sql.= " AND s.rowid = ".$object->id;
  599. $sql.= " AND c.entity = ".$conf->entity;
  600. $sql.= " ORDER BY c.date_commande DESC";
  601. $resql=$db->query($sql);
  602. if ($resql)
  603. {
  604. $var=true;
  605. $num = $db->num_rows($resql);
  606. if ($num > 0)
  607. {
  608. // Check if there are orders billable
  609. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  610. $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
  611. $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  612. $sql2.= ', '.MAIN_DB_PREFIX.'commande as c';
  613. $sql2.= ' WHERE c.fk_soc = s.rowid';
  614. $sql2.= ' AND s.rowid = '.$object->id;
  615. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  616. $sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  617. $resql2=$db->query($sql2);
  618. $orders2invoice = $db->num_rows($resql2);
  619. $db->free($resql2);
  620. print '<table class="noborder" width="100%">';
  621. print '<tr class="liste_titre">';
  622. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomerOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></a></td>';
  623. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  624. //if($num2 > 0) print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.img_picto($langs->trans("CreateInvoiceForThisCustomer"),'object_bill').'</a></td>';
  625. //else print '<td width="20px" align="right"><a href="#">'.img_picto($langs->trans("NoOrdersToInvoice"),'object_bill').'</a></td>';
  626. print '</tr></table></td>';
  627. print '</tr>';
  628. }
  629. $i = 0;
  630. while ($i < $num && $i < $MAXLIST)
  631. {
  632. $objp = $db->fetch_object($resql);
  633. print '<tr class="oddeven">';
  634. print '<td class="nowrap">';
  635. $commande_static->id = $objp->cid;
  636. $commande_static->ref = $objp->ref;
  637. $commande_static->ref_client=$objp->ref_client;
  638. $commande_static->total_ht = $objp->total_ht;
  639. $commande_static->total_tva = $objp->total_tva;
  640. $commande_static->total_ttc = $objp->total_ttc;
  641. print $commande_static->getNomUrl(1);
  642. print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  643. print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  644. print '<td align="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
  645. $i++;
  646. }
  647. $db->free($resql);
  648. if ($num >0) print "</table>";
  649. }
  650. else
  651. {
  652. dol_print_error($db);
  653. }
  654. }
  655. /*
  656. * Last sendings
  657. */
  658. if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
  659. $sendingstatic = new Expedition($db);
  660. $sql = 'SELECT e.rowid as id';
  661. $sql.= ', e.ref';
  662. $sql.= ', e.date_creation';
  663. $sql.= ', e.fk_statut as statut';
  664. $sql.= ', s.nom';
  665. $sql.= ', s.rowid as socid';
  666. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
  667. $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id;
  668. $sql.= " AND e.entity IN (".getEntity('expedition').")";
  669. $sql.= ' GROUP BY e.rowid';
  670. $sql.= ', e.ref';
  671. $sql.= ', e.date_creation';
  672. $sql.= ', e.fk_statut';
  673. $sql.= ', s.nom';
  674. $sql.= ', s.rowid';
  675. $sql.= " ORDER BY e.date_creation DESC";
  676. $resql = $db->query($sql);
  677. if ($resql) {
  678. $var = true;
  679. $num = $db->num_rows($resql);
  680. $i = 0;
  681. if ($num > 0) {
  682. print '<table class="noborder" width="100%">';
  683. print '<tr class="liste_titre">';
  684. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastSendings",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expedition/list.php?socid='.$object->id.'">'.$langs->trans("AllSendings").' <span class="badge">'.$num.'</span></a></td>';
  685. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/expedition/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  686. print '</tr></table></td>';
  687. print '</tr>';
  688. }
  689. while ($i < $num && $i < $MAXLIST) {
  690. $objp = $db->fetch_object($resql);
  691. print '<tr class="oddeven">';
  692. print '<td class="nowrap">';
  693. $sendingstatic->id = $objp->id;
  694. $sendingstatic->ref = $objp->ref;
  695. print $sendingstatic->getNomUrl(1);
  696. print '</td>';
  697. if ($objp->date_creation > 0) {
  698. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
  699. } else {
  700. print '<td align="right"><b>!!!</b></td>';
  701. }
  702. print '<td align="right" class="nowrap" width="100" >' . $sendingstatic->LibStatut($objp->statut, 5) . '</td>';
  703. print "</tr>\n";
  704. $i++;
  705. }
  706. $db->free($resql);
  707. if ($num > 0)
  708. print "</table>";
  709. } else {
  710. dol_print_error($db);
  711. }
  712. }
  713. /*
  714. * Last linked contracts
  715. */
  716. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  717. {
  718. $contratstatic=new Contrat($db);
  719. $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, c.datec as dc, c.date_contrat as dcon, c.ref_supplier as refsup";
  720. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
  721. $sql.= " WHERE c.fk_soc = s.rowid ";
  722. $sql.= " AND s.rowid = ".$object->id;
  723. $sql.= " AND c.entity = ".$conf->entity;
  724. $sql.= " ORDER BY c.datec DESC";
  725. $resql=$db->query($sql);
  726. if ($resql)
  727. {
  728. $var=true;
  729. $num = $db->num_rows($resql);
  730. if ($num >0 )
  731. {
  732. print '<table class="noborder" width="100%">';
  733. print '<tr class="liste_titre">';
  734. print '<td colspan="6"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
  735. print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' <span class="badge">'.$num.'</span></a></td>';
  736. //print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/contract/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  737. print '</tr></table></td>';
  738. print '</tr>';
  739. }
  740. $i = 0;
  741. while ($i < $num && $i < $MAXLIST)
  742. {
  743. $contrat=new Contrat($db);
  744. $objp = $db->fetch_object($resql);
  745. print '<tr class="oddeven">';
  746. print '<td class="nowrap">';
  747. $contrat->id=$objp->id;
  748. $contrat->ref=$objp->ref?$objp->ref:$objp->id;
  749. print $contrat->getNomUrl(1,12);
  750. print "</td>\n";
  751. print '<td class="nowrap">'.dol_trunc($objp->refsup,12)."</td>\n";
  752. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  753. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dcon),'day')."</td>\n";
  754. print '<td width="20">&nbsp;</td>';
  755. print '<td align="right" class="nowrap">';
  756. $contrat->fetch_lines();
  757. print $contrat->getLibStatut(4);
  758. print "</td>\n";
  759. print '</tr>';
  760. $i++;
  761. }
  762. $db->free($resql);
  763. if ($num > 0) print "</table>";
  764. }
  765. else
  766. {
  767. dol_print_error($db);
  768. }
  769. }
  770. /*
  771. * Last interventions
  772. */
  773. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
  774. {
  775. $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
  776. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
  777. $sql.= " WHERE f.fk_soc = s.rowid";
  778. $sql.= " AND s.rowid = ".$object->id;
  779. $sql.= " AND f.entity = ".$conf->entity;
  780. $sql.= " ORDER BY f.tms DESC";
  781. $fichinter_static=new Fichinter($db);
  782. $resql=$db->query($sql);
  783. if ($resql)
  784. {
  785. $var=true;
  786. $num = $db->num_rows($resql);
  787. if ($num > 0)
  788. {
  789. print '<table class="noborder" width="100%">';
  790. print '<tr class="liste_titre">';
  791. print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' <span class="badge">'.$num.'</span></td>';
  792. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/fichinter/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  793. print '</tr></table></td>';
  794. print '</tr>';
  795. }
  796. $i = 0;
  797. while ($i < $num && $i < $MAXLIST)
  798. {
  799. $objp = $db->fetch_object($resql);
  800. $fichinter_static->id=$objp->id;
  801. $fichinter_static->statut=$objp->fk_statut;
  802. print '<tr class="oddeven">';
  803. print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$objp->id.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a></td>'."\n";
  804. //print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
  805. print '<td align="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
  806. print '<td align="right" class="nowrap" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
  807. print '</tr>';
  808. $i++;
  809. }
  810. $db->free($resql);
  811. if ($num > 0) print "</table>";
  812. }
  813. else
  814. {
  815. dol_print_error($db);
  816. }
  817. }
  818. /*
  819. * Last invoices
  820. */
  821. if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
  822. {
  823. $facturestatic = new Facture($db);
  824. $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount';
  825. $sql.= ', f.total as total_ht';
  826. $sql.= ', f.tva as total_tva';
  827. $sql.= ', f.total_ttc';
  828. $sql.= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut';
  829. $sql.= ', s.nom, s.rowid as socid';
  830. $sql.= ', SUM(pf.amount) as am';
  831. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
  832. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
  833. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
  834. $sql.= " AND f.entity = ".$conf->entity;
  835. $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.tva, f.total_ttc,';
  836. $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
  837. $sql.= ' s.nom, s.rowid';
  838. $sql.= " ORDER BY f.datef DESC, f.datec DESC";
  839. $resql=$db->query($sql);
  840. if ($resql)
  841. {
  842. $var=true;
  843. $num = $db->num_rows($resql);
  844. $i = 0;
  845. if ($num > 0)
  846. {
  847. print '<table class="noborder" width="100%">';
  848. print '<tr class="liste_titre">';
  849. print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllBills").' <span class="badge">'.$num.'</span></a></td>';
  850. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  851. print '</tr></table></td>';
  852. print '</tr>';
  853. }
  854. while ($i < $num && $i < $MAXLIST)
  855. {
  856. $objp = $db->fetch_object($resql);
  857. print '<tr class="oddeven">';
  858. print '<td class="nowrap">';
  859. $facturestatic->id = $objp->facid;
  860. $facturestatic->ref = $objp->facnumber;
  861. $facturestatic->type = $objp->type;
  862. $facturestatic->total_ht = $objp->total_ht;
  863. $facturestatic->total_tva = $objp->total_tva;
  864. $facturestatic->total_ttc = $objp->total_ttc;
  865. print $facturestatic->getNomUrl(1);
  866. print '</td>';
  867. if ($objp->df > 0)
  868. {
  869. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->df),'day').'</td>';
  870. }
  871. else
  872. {
  873. print '<td align="right"><b>!!!</b></td>';
  874. }
  875. print '<td align="right" style="min-width: 60px">';
  876. print price($objp->total_ht);
  877. print '</td>';
  878. if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
  879. {
  880. print '<td align="right" style="min-width: 60px">';
  881. print price($objp->total_ttc);
  882. print '</td>';
  883. }
  884. print '<td align="right" class="nowrap" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).'</td>';
  885. print "</tr>\n";
  886. $i++;
  887. }
  888. $db->free($resql);
  889. if ($num > 0) print "</table>";
  890. }
  891. else
  892. {
  893. dol_print_error($db);
  894. }
  895. }
  896. print '</div></div></div>';
  897. print '<div style="clear:both"></div>';
  898. dol_fiche_end();
  899. /*
  900. * Barre d'actions
  901. */
  902. print '<div class="tabsAction">';
  903. $parameters = array();
  904. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  905. if (empty($reshook))
  906. {
  907. if ($object->status != 1)
  908. {
  909. print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  910. }
  911. if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1)
  912. {
  913. $langs->load("propal");
  914. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddProp").'</a></div>';
  915. }
  916. if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1)
  917. {
  918. $langs->load("orders");
  919. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a></div>';
  920. }
  921. if ($user->rights->contrat->creer && $object->status==1)
  922. {
  923. $langs->load("contracts");
  924. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContract").'</a></div>';
  925. }
  926. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1)
  927. {
  928. $langs->load("fichinter");
  929. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a></div>';
  930. }
  931. // Add invoice
  932. if ($user->societe_id == 0)
  933. {
  934. if (! empty($conf->deplacement->enabled) && $object->status==1)
  935. {
  936. $langs->load("trips");
  937. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a></div>';
  938. }
  939. if (! empty($conf->facture->enabled) && $object->status==1)
  940. {
  941. if (empty($user->rights->facture->creer))
  942. {
  943. print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  944. }
  945. else
  946. {
  947. $langs->load("bills");
  948. $langs->load("orders");
  949. if (! empty($conf->commande->enabled))
  950. {
  951. if ($object->client != 0 && $object->client != 2)
  952. {
  953. if (! empty($orders2invoice) && $orders2invoice > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  954. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  955. }
  956. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  957. }
  958. if ($object->client != 0 && $object->client != 2) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a></div>';
  959. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  960. }
  961. }
  962. }
  963. // Add action
  964. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
  965. {
  966. if ($user->rights->agenda->myactions->create)
  967. {
  968. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a></div>';
  969. }
  970. else
  971. {
  972. print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
  973. }
  974. }
  975. }
  976. print '</div>';
  977. if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
  978. {
  979. // List of contacts
  980. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  981. }
  982. // Addresses list
  983. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  984. {
  985. show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  986. }
  987. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  988. {
  989. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  990. // List of todo actions
  991. show_actions_todo($conf,$langs,$db,$object);
  992. // List of done actions
  993. show_actions_done($conf,$langs,$db,$object);
  994. }
  995. }
  996. else
  997. {
  998. dol_print_error($db,'Bad value for socid parameter');
  999. }
  1000. // End of page
  1001. llxFooter();
  1002. $db->close();