card.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. <?php
  2. /* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2016-2018 Frédéric France <frederic.france@netlogic.fr>
  5. * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/sociales/card.php
  22. * \ingroup tax
  23. * \brief Social contribution card page
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  31. if (! empty($conf->projet->enabled))
  32. {
  33. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. }
  36. if (! empty($conf->accounting->enabled)) {
  37. include_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('compta', 'bills', 'banks'));
  41. $id=GETPOST('id','int');
  42. $action=GETPOST('action','aZ09');
  43. $confirm=GETPOST('confirm');
  44. $projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
  45. // Security check
  46. $socid = GETPOST('socid','int');
  47. if ($user->societe_id) $socid=$user->societe_id;
  48. $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
  49. $object = new ChargeSociales($db);
  50. /* *************************************************************************** */
  51. /* */
  52. /* Actions */
  53. /* */
  54. /* *************************************************************************** */
  55. // Classify paid
  56. if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes')
  57. {
  58. $object->fetch($id);
  59. $result = $object->set_paid($user);
  60. }
  61. if ($action == 'reopen' && $user->rights->tax->charges->creer) {
  62. $result = $object->fetch($id);
  63. if ($object->paye)
  64. {
  65. $result = $object->set_unpaid($user);
  66. if ($result > 0)
  67. {
  68. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
  69. exit();
  70. } else {
  71. setEventMessages($object->error, $object->errors, 'errors');
  72. }
  73. }
  74. }
  75. // Link to a project
  76. if ($action == 'classin' && $user->rights->tax->charges->creer)
  77. {
  78. $object->fetch($id);
  79. $object->setProject(GETPOST('projectid'));
  80. }
  81. if ($action == 'setlib' && $user->rights->tax->charges->creer)
  82. {
  83. $object->fetch($id);
  84. $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY');
  85. if ($result < 0)
  86. setEventMessages($object->error, $object->errors, 'errors');
  87. }
  88. // payment mode
  89. if ($action == 'setmode' && $user->rights->tax->charges->creer) {
  90. $object->fetch($id);
  91. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  92. if ($result < 0)
  93. setEventMessages($object->error, $object->errors, 'errors');
  94. }
  95. // bank account
  96. if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
  97. $object->fetch($id);
  98. $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
  99. if ($result < 0) {
  100. setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. }
  103. // Delete social contribution
  104. if ($action == 'confirm_delete' && $confirm == 'yes')
  105. {
  106. $object->fetch($id);
  107. $result=$object->delete($user);
  108. if ($result > 0)
  109. {
  110. header("Location: index.php");
  111. exit;
  112. }
  113. else
  114. {
  115. setEventMessages($object->error, $object->errors, 'errors');
  116. }
  117. }
  118. // Add social contribution
  119. if ($action == 'add' && $user->rights->tax->charges->creer)
  120. {
  121. $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear'));
  122. $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear'));
  123. $amount=price2num(GETPOST('amount'));
  124. $actioncode=GETPOST('actioncode');
  125. if (! $dateech)
  126. {
  127. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors');
  128. $action = 'create';
  129. }
  130. elseif (! $dateperiod)
  131. {
  132. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
  133. $action = 'create';
  134. }
  135. elseif (! $actioncode > 0)
  136. {
  137. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  138. $action = 'create';
  139. }
  140. elseif (empty($amount))
  141. {
  142. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  143. $action = 'create';
  144. }
  145. elseif (! is_numeric($amount))
  146. {
  147. setEventMessages($langs->trans("ErrorFieldMustBeANumeric",$langs->transnoentities("Amount")), null, 'errors');
  148. $action = 'create';
  149. }
  150. else
  151. {
  152. $object->type = $actioncode;
  153. $object->lib = GETPOST('label');
  154. $object->date_ech = $dateech;
  155. $object->periode = $dateperiod;
  156. $object->amount = $amount;
  157. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  158. $object->fk_account = GETPOST('fk_account', 'int');
  159. $object->fk_project = GETPOST('fk_project');
  160. $id=$object->create($user);
  161. if ($id <= 0)
  162. {
  163. setEventMessages($object->error, $object->errors, 'errors');
  164. $action='create';
  165. }
  166. }
  167. }
  168. if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer)
  169. {
  170. $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear'));
  171. $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear'));
  172. $amount=price2num(GETPOST('amount'));
  173. if (! $dateech)
  174. {
  175. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors');
  176. $action = 'edit';
  177. }
  178. elseif (! $dateperiod)
  179. {
  180. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
  181. $action = 'edit';
  182. }
  183. elseif (empty($amount))
  184. {
  185. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  186. $action = 'edit';
  187. }
  188. elseif (! is_numeric($amount))
  189. {
  190. setEventMessages($langs->trans("ErrorFieldMustBeANumeric",$langs->transnoentities("Amount")), null, 'errors');
  191. $action = 'create';
  192. }
  193. else
  194. {
  195. $result=$object->fetch($id);
  196. $object->date_ech = $dateech;
  197. $object->periode = $dateperiod;
  198. $object->amount = price2num($amount);
  199. $result=$object->update($user);
  200. if ($result <= 0)
  201. {
  202. setEventMessages($object->error, $object->errors, 'errors');
  203. }
  204. }
  205. }
  206. // Action clone object
  207. if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; }
  208. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer))
  209. {
  210. $db->begin();
  211. $originalId = $id;
  212. $object->fetch($id);
  213. if ($object->id > 0)
  214. {
  215. $object->paye = 0;
  216. $object->id = $object->ref = null;
  217. $object->lib = $langs->trans("CopyOf").' '.$object->lib;
  218. if (GETPOST('clone_for_next_month') != '')
  219. {
  220. $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
  221. $object->periode = dol_time_plus_duree($object->periode, 1, 'm');
  222. }
  223. if ($object->check())
  224. {
  225. $id = $object->create($user);
  226. if ($id > 0)
  227. {
  228. $db->commit();
  229. $db->close();
  230. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  231. exit;
  232. }
  233. else
  234. {
  235. $id=$originalId;
  236. $db->rollback();
  237. setEventMessages($object->error,$object->errors, 'errors');
  238. }
  239. }
  240. }
  241. else
  242. {
  243. $db->rollback();
  244. dol_print_error($db,$object->error);
  245. }
  246. }
  247. /*
  248. * View
  249. */
  250. $form = new Form($db);
  251. $formsocialcontrib = new FormSocialContrib($db);
  252. $bankaccountstatic = new Account($db);
  253. if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  254. $title = $langs->trans("SocialContribution") . ' - ' . $langs->trans("Card");
  255. $help_url='EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
  256. llxHeader("",$title,$help_url);
  257. // Mode creation
  258. if ($action == 'create')
  259. {
  260. print load_fiche_titre($langs->trans("NewSocialContribution"));
  261. print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
  262. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  263. print '<input type="hidden" name="action" value="add">';
  264. dol_fiche_head();
  265. print '<table class="border" width="100%">';
  266. // Label
  267. print "<tr>";
  268. print '<td class="titlefieldcreate fieldrequired">';
  269. print $langs->trans("Label");
  270. print '</td>';
  271. print '<td><input type="text" size="34" name="label" class="flat" value="'.dol_escape_htmltag(GETPOST('label','alpha')).'" autofocus></td>';
  272. print '</tr>';
  273. print '<tr>';
  274. // Type
  275. print '<td class="fieldrequired">';
  276. print $langs->trans("Type");
  277. print '</td>';
  278. print '<td>';
  279. $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode",'alpha')?GETPOST("actioncode",'alpha'):'','actioncode',1);
  280. print '</td>';
  281. print '</tr>';
  282. // Date end period
  283. print '<tr>';
  284. print '<td class="fieldrequired">';
  285. print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
  286. print '</td>';
  287. print '<td>';
  288. print $form->selectDate(! empty($dateperiod)?$dateperiod:'-1', 'period', 0, 0, 0, 'charge', 1);
  289. print '</td>';
  290. print '</tr>';
  291. // Date due
  292. print '<tr>';
  293. print '<td class="fieldrequired">';
  294. print $langs->trans("DateDue");
  295. print '</td>';
  296. print '<td>';
  297. print $form->selectDate(! empty($dateech)?$dateech:'-1', 'ech', 0, 0, 0, 'charge', 1);
  298. print '</td>';
  299. print "</tr>\n";
  300. // Amount
  301. print '<tr>';
  302. print '<td class="fieldrequired">';
  303. print $langs->trans("Amount");
  304. print '</td>';
  305. print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount','alpha')).'"></td>';
  306. print '</tr>';
  307. // Project
  308. if (! empty($conf->projet->enabled))
  309. {
  310. $formproject=new FormProjets($db);
  311. // Associated project
  312. $langs->load("projects");
  313. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  314. $numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1);
  315. print '</td></tr>';
  316. }
  317. // Payment Mode
  318. print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td colspan="2">';
  319. $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id');
  320. print '</td></tr>';
  321. // Bank Account
  322. if (! empty($conf->banque->enabled))
  323. {
  324. print '<tr><td>' . $langs->trans('BankAccount') . '</td><td colspan="2">';
  325. $form->select_comptes($fk_account, 'fk_account', 0, '', 1);
  326. print '</td></tr>';
  327. }
  328. print '</table>';
  329. dol_fiche_end();
  330. print '<div class="center">';
  331. print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
  332. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  333. print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
  334. print '</div>';
  335. print '</form>';
  336. }
  337. /* *************************************************************************** */
  338. /* */
  339. /* Card Mode */
  340. /* */
  341. /* *************************************************************************** */
  342. if ($id > 0)
  343. {
  344. $object = new ChargeSociales($db);
  345. $result=$object->fetch($id);
  346. if ($result > 0)
  347. {
  348. $head=tax_prepare_head($object);
  349. $totalpaye = $object->getSommePaiement();
  350. // Clone confirmation
  351. if ($action === 'clone')
  352. {
  353. $formclone=array(
  354. array('type' => 'checkbox', 'name' => 'clone_for_next_month','label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1),
  355. );
  356. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneTax'),$langs->trans('ConfirmCloneTax',$object->ref),'confirm_clone',$formclone,'yes');
  357. }
  358. // Confirmation de la suppression de la charge
  359. if ($action == 'paid')
  360. {
  361. $text=$langs->trans('ConfirmPaySocialContribution');
  362. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PaySocialContribution'),$text,"confirm_paid",'','',2);
  363. }
  364. if ($action == 'delete')
  365. {
  366. $text=$langs->trans('ConfirmDeleteSocialContribution');
  367. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSocialContribution'),$text,'confirm_delete','','',2);
  368. }
  369. if ($action == 'edit')
  370. {
  371. print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
  372. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  373. }
  374. dol_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill');
  375. $morehtmlref='<div class="refidno">';
  376. // Ref customer
  377. $morehtmlref.=$form->editfieldkey("Label", 'lib', $object->lib, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
  378. $morehtmlref.=$form->editfieldval("Label", 'lib', $object->lib, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
  379. // Project
  380. if (! empty($conf->projet->enabled))
  381. {
  382. $langs->load("projects");
  383. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  384. if ($user->rights->tax->charges->creer)
  385. {
  386. if ($action != 'classify')
  387. $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  388. if ($action == 'classify') {
  389. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  390. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  391. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  392. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  393. $morehtmlref.=$formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  394. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  395. $morehtmlref.='</form>';
  396. } else {
  397. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  398. }
  399. } else {
  400. if (! empty($object->fk_project)) {
  401. $proj = new Project($db);
  402. $proj->fetch($object->fk_project);
  403. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  404. $morehtmlref.=$proj->ref;
  405. $morehtmlref.='</a>';
  406. } else {
  407. $morehtmlref.='';
  408. }
  409. }
  410. }
  411. $morehtmlref.='</div>';
  412. $linkback = '<a href="' . DOL_URL_ROOT . '/compta/sociales/list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
  413. $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  414. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  415. print '<div class="fichecenter">';
  416. print '<div class="fichehalfleft">';
  417. print '<div class="underbanner clearboth"></div>';
  418. print '<table class="border" width="100%">';
  419. // Type
  420. print '<tr><td class="titlefield">'.$langs->trans("Type")."</td><td>".$object->type_libelle."</td>";
  421. print "</tr>";
  422. // Period end date
  423. print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
  424. print "<td>";
  425. if ($action == 'edit')
  426. {
  427. print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1);
  428. }
  429. else
  430. {
  431. print dol_print_date($object->periode,"day");
  432. }
  433. print "</td></tr>";
  434. // Due date
  435. if ($action == 'edit')
  436. {
  437. print '<tr><td>'.$langs->trans("DateDue")."</td><td>";
  438. print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1);
  439. print "</td></tr>";
  440. } else {
  441. print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($object->date_ech,'day')."</td></tr>";
  442. }
  443. // Amount
  444. if ($action == 'edit')
  445. {
  446. print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
  447. print '<input type="text" name="amount" size="12" class="flat" value="'.$object->amount.'">';
  448. print "</td></tr>";
  449. }
  450. else {
  451. print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
  452. }
  453. // Mode of payment
  454. print '<tr><td>';
  455. print '<table class="nobordernopadding" width="100%"><tr><td>';
  456. print $langs->trans('PaymentMode');
  457. print '</td>';
  458. if ($action != 'editmode')
  459. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetMode'), 1) . '</a></td>';
  460. print '</tr></table>';
  461. print '</td><td>';
  462. if ($action == 'editmode') {
  463. $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id');
  464. } else {
  465. $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none');
  466. }
  467. print '</td></tr>';
  468. // Bank Account
  469. if (! empty($conf->banque->enabled))
  470. {
  471. print '<tr><td class="nowrap">';
  472. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  473. print $langs->trans('BankAccount');
  474. print '<td>';
  475. if ($action != 'editbankaccount' && $user->rights->tax->charges->creer)
  476. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  477. print '</tr></table>';
  478. print '</td><td>';
  479. if ($action == 'editbankaccount') {
  480. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  481. } else {
  482. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  483. }
  484. print '</td>';
  485. print '</tr>';
  486. }
  487. print '</table>';
  488. print '</div>';
  489. print '<div class="fichehalfright">';
  490. print '<div class="ficheaddleft">';
  491. $nbcols = 3;
  492. if (! empty($conf->banque->enabled)) {
  493. $nbcols ++;
  494. }
  495. /*
  496. * Payments
  497. */
  498. $sql = "SELECT p.rowid, p.num_paiement, datep as dp, p.amount,";
  499. $sql.= " c.code as type_code,c.libelle as paiement_type,";
  500. $sql.= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
  501. $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
  502. $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
  503. $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
  504. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
  505. $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  506. $sql.= " WHERE p.fk_charge = ".$id;
  507. $sql.= " AND p.fk_charge = cs.rowid";
  508. $sql.= " AND cs.entity IN (".getEntity('tax').")";
  509. $sql.= " ORDER BY dp DESC";
  510. //print $sql;
  511. $resql = $db->query($sql);
  512. if ($resql)
  513. {
  514. $totalpaye = 0;
  515. $num = $db->num_rows($resql);
  516. $i = 0; $total = 0;
  517. print '<table class="noborder paymenttable">';
  518. print '<tr class="liste_titre">';
  519. print '<td>'.$langs->trans("RefPayment").'</td>';
  520. print '<td>'.$langs->trans("Date").'</td>';
  521. print '<td>'.$langs->trans("Type").'</td>';
  522. if (! empty($conf->banque->enabled)) {
  523. print '<td class="liste_titre" align="right">' . $langs->trans('BankAccount') . '</td>';
  524. }
  525. print '<td align="right">'.$langs->trans("Amount").'</td>';
  526. print '</tr>';
  527. if ($num > 0)
  528. {
  529. while ($i < $num)
  530. {
  531. $objp = $db->fetch_object($resql);
  532. print '<tr class="oddeven"><td>';
  533. print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.'</a></td>';
  534. print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  535. $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type;
  536. print "<td>".$labeltype.' '.$objp->num_paiement."</td>\n";
  537. if (! empty($conf->banque->enabled))
  538. {
  539. $bankaccountstatic->id = $objp->baid;
  540. $bankaccountstatic->ref = $objp->baref;
  541. $bankaccountstatic->label = $objp->baref;
  542. $bankaccountstatic->number = $objp->banumber;
  543. if (! empty($conf->accounting->enabled)) {
  544. $bankaccountstatic->account_number = $objp->account_number;
  545. $accountingjournal = new AccountingJournal($db);
  546. $accountingjournal->fetch($objp->fk_accountancy_journal);
  547. $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
  548. }
  549. print '<td align="right">';
  550. if ($bankaccountstatic->id)
  551. print $bankaccountstatic->getNomUrl(1, 'transactions');
  552. print '</td>';
  553. }
  554. print '<td align="right">'.price($objp->amount)."</td>\n";
  555. print "</tr>";
  556. $totalpaye += $objp->amount;
  557. $i++;
  558. }
  559. }
  560. else
  561. {
  562. print '<tr class="oddeven"><td class="opacitymedium">'.$langs->trans("None").'</td>';
  563. print '<td></td><td></td><td></td><td></td>';
  564. print '</tr>';
  565. }
  566. print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("AlreadyPaid")." :</td><td align=\"right\">".price($totalpaye)."</td></tr>\n";
  567. print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("AmountExpected")." :</td><td align=\"right\">".price($object->amount)."</td></tr>\n";
  568. $resteapayer = $object->amount - $totalpaye;
  569. $cssforamountpaymentcomplete = 'amountpaymentcomplete';
  570. print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("RemainderToPay")." :</td>";
  571. print '<td align="right"'.($resteapayer?' class="amountremaintopay"':(' class="'.$cssforamountpaymentcomplete.'"')).'>'.price($resteapayer)."</td></tr>\n";
  572. print "</table>";
  573. $db->free($resql);
  574. }
  575. else
  576. {
  577. dol_print_error($db);
  578. }
  579. print '</div>';
  580. print '</div>';
  581. print '</div>';
  582. print '<div class="clearboth"></div>';
  583. dol_fiche_end();
  584. if ($action == 'edit')
  585. {
  586. print '<div align="center">';
  587. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  588. print ' &nbsp; ';
  589. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  590. print '</div>';
  591. }
  592. if ($action == 'edit') print "</form>\n";
  593. /*
  594. * Actions buttons
  595. */
  596. if ($action != 'edit')
  597. {
  598. print "<div class=\"tabsAction\">\n";
  599. // Reopen
  600. if ($object->paye && $user->rights->tax->charges->creer)
  601. {
  602. print "<a class=\"butAction\" href=\"".dol_buildpath("/compta/sociales/card.php",1). "?id=$object->id&amp;action=reopen\">".$langs->trans("ReOpen")."</a>";
  603. }
  604. // Edit
  605. if ($object->paye == 0 && $user->rights->tax->charges->creer)
  606. {
  607. print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/card.php?id=$object->id&amp;action=edit\">".$langs->trans("Modify")."</a>";
  608. }
  609. // Emit payment
  610. if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer)
  611. {
  612. print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$object->id&amp;action=create\">".$langs->trans("DoPayment")."</a>";
  613. }
  614. // Classify 'paid'
  615. if ($object->paye == 0 && round($resteapayer) <=0 && $user->rights->tax->charges->creer)
  616. {
  617. print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/card.php?id=$object->id&amp;action=paid\">".$langs->trans("ClassifyPaid")."</a>";
  618. }
  619. // Clone
  620. if ($user->rights->tax->charges->creer)
  621. {
  622. print "<a class=\"butAction\" href=\"".dol_buildpath("/compta/sociales/card.php",1). "?id=$object->id&amp;action=clone\">".$langs->trans("ToClone")."</a>";
  623. }
  624. // Delete
  625. if ($user->rights->tax->charges->supprimer)
  626. {
  627. print "<a class=\"butActionDelete\" href=\"".DOL_URL_ROOT."/compta/sociales/card.php?id=$object->id&amp;action=delete\">".$langs->trans("Delete")."</a>";
  628. }
  629. print "</div>";
  630. }
  631. }
  632. else
  633. {
  634. /* Social contribution not found */
  635. dol_print_error('',$object->error);
  636. }
  637. }
  638. // End of page
  639. llxFooter();
  640. $db->close();