card.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. <?php
  2. /* Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2014-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  5. * Copyright (C) 2015 Charlie BENKE <charlie@patas-monkey.com>
  6. * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
  7. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/salaries/card.php
  24. * \ingroup salaries
  25. * \brief Page of salaries payments
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. if (!empty($conf->projet->enabled)) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  39. }
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips"));
  42. if (!empty($conf->projet->enabled)) {
  43. $langs->load("projects");
  44. }
  45. $id = GETPOSTINT('id');
  46. $ref = GETPOST('ref', 'alpha');
  47. $action = GETPOST('action', 'aZ09');
  48. $cancel = GETPOST('cancel', 'aZ09');
  49. $backtopage = GETPOST('backtopage', 'alpha');
  50. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  51. $confirm = GETPOST('confirm');
  52. $label = GETPOST('label', 'alphanohtml');
  53. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  54. $accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0;
  55. if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
  56. $auto_create_paiement = GETPOST("auto_create_paiement", "int");
  57. } else {
  58. $auto_create_paiement = empty($conf->global->CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT);
  59. }
  60. $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
  61. $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
  62. $datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int'));
  63. $dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int'));
  64. $fk_user = GETPOSTINT('userid');
  65. $object = new Salary($db);
  66. $extrafields = new ExtraFields($db);
  67. $childids = $user->getAllChildIds(1);
  68. // fetch optionals attributes and labels
  69. $extrafields->fetch_name_optionals_label($object->table_element);
  70. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  71. $hookmanager->initHooks(array('salarycard', 'globalcard'));
  72. if ($id > 0 || !empty($ref)) {
  73. $object->fetch($id, $ref);
  74. // Check current user can read this salary
  75. $canread = 0;
  76. if (!empty($user->rights->salaries->readall)) {
  77. $canread = 1;
  78. }
  79. if (!empty($user->rights->salaries->read) && $object->fk_user > 0 && in_array($object->fk_user, $childids)) {
  80. $canread = 1;
  81. }
  82. if (!$canread) {
  83. accessforbidden();
  84. }
  85. }
  86. // Security check
  87. $socid = GETPOSTINT('socid');
  88. if ($user->socid) {
  89. $socid = $user->socid;
  90. }
  91. restrictedArea($user, 'salaries', $object->id, 'salary', '');
  92. $permissiontoread = $user->rights->salaries->read;
  93. $permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  94. $permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  95. /**
  96. * Actions
  97. */
  98. $parameters = array();
  99. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  100. if ($reshook < 0) {
  101. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  102. }
  103. if (empty($reshook)) {
  104. $error = 0;
  105. $backurlforlist = dol_buildpath('/salaries/list.php', 1);
  106. if (empty($backtopage) || ($cancel && empty($id))) {
  107. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  108. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  109. $backtopage = $backurlforlist;
  110. } else {
  111. $backtopage = dol_buildpath('/salaries/card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  112. }
  113. }
  114. }
  115. if ($cancel) {
  116. //var_dump($cancel);
  117. //var_dump($backtopage);exit;
  118. if (!empty($backtopageforcancel)) {
  119. header("Location: ".$backtopageforcancel);
  120. exit;
  121. } elseif (!empty($backtopage)) {
  122. header("Location: ".$backtopage);
  123. exit;
  124. }
  125. $action = '';
  126. }
  127. }
  128. // Link to a project
  129. if ($action == 'classin' && $user->rights->banque->modifier) {
  130. $object->fetch($id);
  131. $object->setProject($projectid);
  132. }
  133. // set label
  134. if ($action == 'setlabel' && $user->rights->salaries->write) {
  135. $object->fetch($id);
  136. $object->label = $label;
  137. $object->update($user);
  138. }
  139. // Classify paid
  140. if ($action == 'confirm_paid' && $user->rights->salaries->write && $confirm == 'yes') {
  141. $object->fetch($id);
  142. $result = $object->set_paid($user);
  143. }
  144. if ($action == 'setfk_user' && $user->rights->salaries->write) {
  145. $result = $object->fetch($id);
  146. if ($result > 0) {
  147. $object->fk_user = $fk_user;
  148. $object->update($user);
  149. } else {
  150. dol_print_error($db);
  151. exit;
  152. }
  153. }
  154. if ($action == 'reopen' && $user->rights->salaries->write) {
  155. $result = $object->fetch($id);
  156. if ($object->paye) {
  157. $result = $object->set_unpaid($user);
  158. if ($result > 0) {
  159. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  160. exit();
  161. } else {
  162. setEventMessages($object->error, $object->errors, 'errors');
  163. }
  164. }
  165. }
  166. // payment mode
  167. if ($action == 'setmode' && $user->rights->salaries->write) {
  168. $object->fetch($id);
  169. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  170. if ($result < 0)
  171. setEventMessages($object->error, $object->errors, 'errors');
  172. }
  173. // bank account
  174. if ($action == 'setbankaccount' && $user->rights->salaries->write) {
  175. $object->fetch($id);
  176. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  177. if ($result < 0) {
  178. setEventMessages($object->error, $object->errors, 'errors');
  179. }
  180. }
  181. if ($action == 'add' && empty($cancel)) {
  182. $error = 0;
  183. if (empty($datev)) $datev = $datep;
  184. $type_payment = GETPOST("paymenttype", 'alpha');
  185. $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2);
  186. $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
  187. $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", "int") : 0;
  188. $object->datev = $datev;
  189. $object->datep = $datep;
  190. $object->amount = $amount;
  191. $object->label = GETPOST("label", 'alphanohtml');
  192. $object->datesp = $datesp;
  193. $object->dateep = $dateep;
  194. $object->note = GETPOST("note", 'restricthtml');
  195. $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
  196. $object->fk_user_author = $user->id;
  197. $object->fk_project = $projectid;
  198. // Set user current salary as ref salary for the payment
  199. $fuser = new User($db);
  200. $fuser->fetch(GETPOST("fk_user", "int"));
  201. $object->salary = $fuser->salary;
  202. // Fill array 'array_options' with data from add form
  203. $ret = $extrafields->setOptionalsFromPost(null, $object);
  204. if ($ret < 0) {
  205. $error++;
  206. }
  207. if (!empty($auto_create_paiement) && empty($datep)) {
  208. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors');
  209. $error++;
  210. }
  211. if (empty($datesp) || empty($dateep)) {
  212. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  213. $error++;
  214. }
  215. if (empty($object->fk_user) || $object->fk_user < 0) {
  216. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Employee")), null, 'errors');
  217. $error++;
  218. }
  219. if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) {
  220. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
  221. $error++;
  222. }
  223. if (empty($object->amount)) {
  224. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  225. $error++;
  226. }
  227. if (!empty($conf->banque->enabled) && !empty($auto_create_paiement) && !$object->accountid > 0) {
  228. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
  229. $error++;
  230. }
  231. if (!$error) {
  232. $db->begin();
  233. $ret = $object->create($user);
  234. if ($ret < 0) {
  235. setEventMessages($object->error, $object->errors, 'errors');
  236. $error++;
  237. }
  238. if (!empty($auto_create_paiement) && !$error) {
  239. // Create a line of payments
  240. $paiement = new PaymentSalary($db);
  241. $paiement->chid = $object->id;
  242. $paiement->datepaye = $datep;
  243. $paiement->datev = $datev;
  244. $paiement->amounts = array($object->id=>$amount); // Tableau de montant
  245. $paiement->paiementtype = $type_payment;
  246. $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
  247. $paiement->note = GETPOST("note", 'restricthtml');
  248. if (!$error) {
  249. $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary'));
  250. if ($paymentid < 0) {
  251. $error++;
  252. setEventMessages($paiement->error, null, 'errors');
  253. $action = 'create';
  254. }
  255. }
  256. if (!$error) {
  257. $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', '');
  258. if (!($result > 0)) {
  259. $error++;
  260. setEventMessages($paiement->error, null, 'errors');
  261. }
  262. }
  263. }
  264. if (empty($error)) {
  265. $db->commit();
  266. if (GETPOST('saveandnew', 'alpha')) {
  267. setEventMessages($langs->trans("RecordSaved"), '', 'mesgs');
  268. header("Location: card.php?action=create&fk_project=" . urlencode($projectid) . "&accountid=" . urlencode($accountid) . '&paymenttype=' . urlencode(GETPOST('paymenttype', 'az09')) . '&datepday=' . GETPOST("datepday", 'int') . '&datepmonth=' . GETPOST("datepmonth", 'int') . '&datepyear=' . GETPOST("datepyear", 'int'));
  269. exit;
  270. } else {
  271. header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
  272. exit;
  273. }
  274. } else {
  275. $db->rollback();
  276. }
  277. }
  278. $action = 'create';
  279. }
  280. if ($action == 'confirm_delete') {
  281. $result = $object->fetch($id);
  282. $totalpaid = $object->getSommePaiement();
  283. if (empty($totalpaid)) {
  284. $db->begin();
  285. $ret = $object->delete($user);
  286. if ($ret > 0) {
  287. $db->commit();
  288. header("Location: ".DOL_URL_ROOT.'/salaries/list.php');
  289. exit;
  290. } else {
  291. $db->rollback();
  292. setEventMessages($object->error, $object->errors, 'errors');
  293. }
  294. } else {
  295. setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
  296. }
  297. }
  298. if ($action == 'update' && !GETPOST("cancel") && $user->rights->salaries->write) {
  299. $amount = price2num(GETPOST('amount'), 'MT', 2);
  300. if (empty($amount)) {
  301. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  302. $action = 'edit';
  303. } elseif (!is_numeric($amount)) {
  304. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
  305. $action = 'create';
  306. } else {
  307. $result = $object->fetch($id);
  308. $object->amount = price2num($amount);
  309. $object->datesp = price2num($datesp);
  310. $object->dateep = price2num($dateep);
  311. $result = $object->update($user);
  312. if ($result <= 0) {
  313. setEventMessages($object->error, $object->errors, 'errors');
  314. }
  315. }
  316. }
  317. if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
  318. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->salaries->write)) {
  319. $db->begin();
  320. $originalId = $id;
  321. $object->fetch($id);
  322. if ($object->id > 0) {
  323. $object->paye = 0;
  324. $object->id = $object->ref = null;
  325. if (GETPOST('clone_label', 'alphanohtml')) {
  326. $object->label = GETPOST('clone_label', 'alphanohtml');
  327. } else {
  328. $object->label = $langs->trans("CopyOf").' '.$object->label;
  329. }
  330. $newdatestart = dol_mktime(0, 0, 0, GETPOST('clone_date_startmonth', 'int'), GETPOST('clone_date_startday', 'int'), GETPOST('clone_date_startyear', 'int'));
  331. $newdateend = dol_mktime(0, 0, 0, GETPOST('clone_date_endmonth', 'int'), GETPOST('clone_date_endday', 'int'), GETPOST('clone_date_endyear', 'int'));
  332. if ($newdatestart) $object->datesp = $newdatestart;
  333. if ($newdateend) $object->dateep = $newdateend;
  334. $id = $object->create($user);
  335. if ($id > 0) {
  336. $db->commit();
  337. $db->close();
  338. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  339. exit;
  340. } else {
  341. $id = $originalId;
  342. $db->rollback();
  343. setEventMessages($object->error, $object->errors, 'errors');
  344. }
  345. } else {
  346. $db->rollback();
  347. dol_print_error($db, $object->error);
  348. }
  349. }
  350. // Action to update one extrafield
  351. if ($action == "update_extras" && !empty($user->rights->salaries->read)) {
  352. $object->fetch(GETPOST('id', 'int'));
  353. $attributekey = GETPOST('attribute', 'alpha');
  354. $attributekeylong = 'options_'.$attributekey;
  355. if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
  356. // This is properties of a date
  357. $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
  358. //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
  359. } else {
  360. $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
  361. }
  362. $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
  363. if ($result > 0) {
  364. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  365. $action = 'view';
  366. } else {
  367. setEventMessages($object->error, $object->errors, 'errors');
  368. $action = 'edit_extras';
  369. }
  370. }
  371. /*
  372. * View
  373. */
  374. $form = new Form($db);
  375. $formfile = new FormFile($db);
  376. if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);
  377. $title = $langs->trans('Salary')." - ".$langs->trans('Card');
  378. $help_url = "";
  379. llxHeader("", $title, $help_url);
  380. if ($id > 0) {
  381. $result = $object->fetch($id);
  382. if ($result <= 0) {
  383. dol_print_error($db);
  384. exit;
  385. }
  386. }
  387. // Create
  388. if ($action == 'create') {
  389. $year_current = strftime("%Y", dol_now());
  390. $pastmonth = strftime("%m", dol_now()) - 1;
  391. $pastmonthyear = $year_current;
  392. if ($pastmonth == 0) {
  393. $pastmonth = 12;
  394. $pastmonthyear--;
  395. }
  396. $datespmonth = GETPOST('datespmonth', 'int');
  397. $datespday = GETPOST('datespday', 'int');
  398. $datespyear = GETPOST('datespyear', 'int');
  399. $dateepmonth = GETPOST('dateepmonth', 'int');
  400. $dateepday = GETPOST('dateepday', 'int');
  401. $dateepyear = GETPOST('dateepyear', 'int');
  402. $datesp = dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
  403. $dateep = dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
  404. if (empty($datesp) || empty($dateep)) { // We define date_start and date_end
  405. $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false); $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false);
  406. }
  407. print '<form name="salary" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  408. print '<input type="hidden" name="token" value="'.newToken().'">';
  409. print '<input type="hidden" name="action" value="add">';
  410. if ($backtopage) {
  411. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  412. }
  413. if ($backtopageforcancel) {
  414. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  415. }
  416. print load_fiche_titre($langs->trans("NewSalary"), '', 'salary');
  417. if (!empty($conf->use_javascript_ajax)) {
  418. print "\n".'<script type="text/javascript">';
  419. print /** @lang JavaScript */'
  420. $(document).ready(function () {
  421. let onAutoCreatePaiementChange = function () {
  422. if($("#auto_create_paiement").is(":checked")) {
  423. $("#label_fk_account").find("span").addClass("fieldrequired");
  424. $("#label_type_payment").find("span").addClass("fieldrequired");
  425. $(".hide_if_no_auto_create_payment").show();
  426. } else {
  427. $("#label_fk_account").find("span").removeClass("fieldrequired");
  428. $("#label_type_payment").find("span").removeClass("fieldrequired");
  429. $(".hide_if_no_auto_create_payment").hide();
  430. }
  431. };
  432. $("#radiopayment").click(function() {
  433. $("#label").val($(this).data("label"));
  434. });
  435. $("#radiorefund").click(function() {
  436. $("#label").val($(this).data("label"));
  437. });
  438. $("#auto_create_paiement").click(function () {
  439. onAutoCreatePaiementChange();
  440. });
  441. onAutoCreatePaiementChange();
  442. });
  443. ';
  444. print '</script>'."\n";
  445. }
  446. print dol_get_fiche_head('', '');
  447. print '<table class="border centpercent">';
  448. // Employee
  449. print '<tr><td class="titlefieldcreate">';
  450. print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).'</td><td>';
  451. $noactive = 0; // We keep active and unactive users
  452. print img_picto('', 'user', 'class="paddingrighonly"').$form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive);
  453. print '</td></tr>';
  454. // Label
  455. print '<tr><td>';
  456. print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
  457. print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST("label") ?GETPOST("label") : $langs->trans("Salary")).'">';
  458. print '</td></tr>';
  459. // Date start period
  460. print '<tr><td>';
  461. print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).'</td><td>';
  462. print $form->selectDate($datesp, "datesp", '', '', '', 'add');
  463. print '</td></tr>';
  464. // Date end period
  465. print '<tr><td>';
  466. print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).'</td><td>';
  467. print $form->selectDate($dateep, "dateep", '', '', '', 'add');
  468. print '</td></tr>';
  469. // Amount
  470. print '<tr><td>';
  471. print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
  472. print '<input name="amount" id="amount" class="minwidth75 maxwidth100" value="'.GETPOST("amount").'">&nbsp;';
  473. print '<button class="dpInvisibleButtons datenow" id="updateAmountWithLastSalary" name="_useless" type="button">'.$langs->trans('UpdateAmountWithLastSalary').'</a>';
  474. print '</td>';
  475. print '</tr>';
  476. // Project
  477. if (!empty($conf->projet->enabled)) {
  478. $formproject = new FormProjets($db);
  479. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  480. print img_picto('', 'project', 'class="pictofixedwidth"');
  481. print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
  482. print '</td></tr>';
  483. }
  484. // Comments
  485. print '<tr>';
  486. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  487. print '<td class="tdtop"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'">'.GETPOST('note', 'restricthtml').'</textarea></td>';
  488. print '</tr>';
  489. print '<tr><td colspan="2"><hr></td></tr>';
  490. // Auto create payment
  491. print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
  492. print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_paiement) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n"; // Date payment
  493. // Bank
  494. if (!empty($conf->banque->enabled)) {
  495. print '<tr><td id="label_fk_account">';
  496. print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
  497. print img_picto('', 'bank_account', 'class="paddingrighonly"');
  498. $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant
  499. print '</td></tr>';
  500. }
  501. // Type payment
  502. print '<tr><td id="label_type_payment">';
  503. print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).'</td><td>';
  504. $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '');
  505. print '</td></tr>';
  506. // Date payment
  507. print '<tr class="hide_if_no_auto_create_payment"><td>';
  508. print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
  509. print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1);
  510. print '</td></tr>';
  511. // Date value for bank
  512. print '<tr class="hide_if_no_auto_create_payment"><td>';
  513. print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
  514. print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
  515. print '</td></tr>';
  516. // Number
  517. if (!empty($conf->banque->enabled)) {
  518. // Number
  519. print '<tr class="hide_if_no_auto_create_payment"><td><label for="num_payment">'.$langs->trans('Numero');
  520. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  521. print '</label></td>';
  522. print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  523. }
  524. // Bouton Save payment
  525. /*
  526. print '<tr class="hide_if_no_auto_create_payment"><td>';
  527. print $langs->trans("ClosePaidSalaryAutomatically");
  528. print '</td><td><input type="checkbox" checked value="1" name="closepaidsalary"></td></tr>';
  529. */
  530. // Other attributes
  531. $parameters = array();
  532. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  533. print $hookmanager->resPrint;
  534. if (empty($reshook)) {
  535. print $object->showOptionals($extrafields, 'create');
  536. }
  537. print '</table>';
  538. print dol_get_fiche_end();
  539. print '<div class="center">';
  540. print '<div class="hide_if_no_auto_create_payment paddingbottom">';
  541. print '<input type="checkbox" checked value="1" name="closepaidsalary">'.$langs->trans("ClosePaidSalaryAutomatically");
  542. print '</div>';
  543. print '</div>';
  544. $addition_button = array(
  545. 'name' => 'saveandnew',
  546. 'label_key' => 'SaveAndNew',
  547. );
  548. print $form->buttonsSaveCancel("Save", "Cancel", $addition_button);
  549. print '</form>';
  550. print '<script>';
  551. print '$( document ).ready(function() {';
  552. print '$("#updateAmountWithLastSalary").on("click", function updateAmountWithLastSalary() {
  553. console.log("We click on link to autofill salary amount");
  554. var fk_user = $("#fk_user").val()
  555. var url = "'.DOL_URL_ROOT.'/salaries/ajax/ajaxsalaries.php?fk_user="+fk_user;
  556. if (fk_user != -1) {
  557. $.get(
  558. url,
  559. function( data ) {
  560. if(data!=null) {
  561. console.log("Data returned: "+data);
  562. item = JSON.parse(data);
  563. if(item[0].key == "Amount") {
  564. value = item[0].value;
  565. if (value != null) {
  566. $("#amount").val(item[0].value);
  567. } else {
  568. console.error("Error: Ajax url "+url+" has returned a null value.");
  569. }
  570. } else {
  571. console.error("Error: Ajax url "+url+" has returned the wrong key.");
  572. }
  573. } else {
  574. console.error("Error: Ajax url "+url+" has returned an empty page.");
  575. }
  576. }
  577. );
  578. } else {
  579. alert("'.dol_escape_js($langs->trans("FillFieldFirst")).'");
  580. }
  581. });
  582. })';
  583. print '</script>';
  584. }
  585. /* ************************************************************************** */
  586. /* */
  587. /* View mode */
  588. /* */
  589. /* ************************************************************************** */
  590. if ($id) {
  591. $head = salaries_prepare_head($object);
  592. $formconfirm = '';
  593. if ($action === 'clone') {
  594. $formquestion = array(
  595. array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
  596. );
  597. //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
  598. $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1);
  599. $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1);
  600. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
  601. }
  602. if ($action == 'paid') {
  603. $text = $langs->trans('ConfirmPaySalary');
  604. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2);
  605. }
  606. if ($action == 'delete') {
  607. $text = $langs->trans('ConfirmDeleteSalary');
  608. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2);
  609. }
  610. if ($action == 'edit') {
  611. print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
  612. print '<input type="hidden" name="token" value="'.newToken().'">';
  613. }
  614. // Call Hook formConfirm
  615. $parameters = array('formConfirm' => $formconfirm);
  616. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  617. if (empty($reshook)) {
  618. $formconfirm .= $hookmanager->resPrint;
  619. } elseif ($reshook > 0) {
  620. $formconfirm = $hookmanager->resPrint;
  621. }
  622. // Print form confirm
  623. print $formconfirm;
  624. print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary');
  625. $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  626. $morehtmlref = '<div class="refidno">';
  627. // Label
  628. if ($action != 'editlabel') {
  629. $morehtmlref .= $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  630. $morehtmlref .= $object->label;
  631. } else {
  632. $morehtmlref .= $langs->trans('Label').' :&nbsp;';
  633. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  634. $morehtmlref .= '<input type="hidden" name="action" value="setlabel">';
  635. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  636. $morehtmlref .= '<input type="text" name="label" value="'.$object->label.'"/>';
  637. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  638. $morehtmlref .= '</form>';
  639. }
  640. // Employee
  641. if ($action != 'editfk_user') {
  642. if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
  643. $userstatic = new User($db);
  644. $result = $userstatic->fetch($object->fk_user);
  645. if ($result > 0) {
  646. $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
  647. }
  648. } else {
  649. $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  650. if (!empty($object->fk_user)) {
  651. $userstatic = new User($db);
  652. $result = $userstatic->fetch($object->fk_user);
  653. if ($result > 0) {
  654. $morehtmlref .= $userstatic->getNomUrl(-1);
  655. } else {
  656. dol_print_error($db);
  657. exit();
  658. }
  659. }
  660. }
  661. } else {
  662. $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
  663. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  664. $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
  665. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  666. $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
  667. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  668. $morehtmlref .= '</form>';
  669. }
  670. // Project
  671. if (!empty($conf->projet->enabled)) {
  672. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  673. if ($user->rights->salaries->write) {
  674. if ($action != 'classify') {
  675. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  676. }
  677. if ($action == 'classify') {
  678. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  679. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  680. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  681. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  682. $morehtmlref .= $formproject->select_projects(-1, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500');
  683. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  684. $morehtmlref .= '</form>';
  685. } else {
  686. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  687. }
  688. } else {
  689. if (!empty($object->fk_project)) {
  690. $proj = new Project($db);
  691. $proj->fetch($object->fk_project);
  692. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  693. if ($proj->title) {
  694. $morehtmlref .= ' - '.$proj->title;
  695. }
  696. } else {
  697. $morehtmlref .= '';
  698. }
  699. }
  700. }
  701. $morehtmlref .= '</div>';
  702. $totalpaid = $object->getSommePaiement();
  703. $object->totalpaid = $totalpaid;
  704. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  705. print '<div class="fichecenter">';
  706. print '<div class="fichehalfleft">';
  707. print '<div class="underbanner clearboth"></div>';
  708. print '<table class="border centpercent tableforfield">';
  709. if ($action == 'edit') {
  710. print '<tr><td class="titlefield">'.$langs->trans("DateStartPeriod")."</td><td>";
  711. print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1);
  712. print "</td></tr>";
  713. } else {
  714. print "<tr>";
  715. print '<td class="titlefield">' . $langs->trans("DateStartPeriod") . '</td><td>';
  716. print dol_print_date($object->datesp, 'day');
  717. print '</td></tr>';
  718. }
  719. if ($action == 'edit') {
  720. print '<tr><td>'.$langs->trans("DateEndPeriod")."</td><td>";
  721. print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1);
  722. print "</td></tr>";
  723. } else {
  724. print "<tr>";
  725. print '<td>' . $langs->trans("DateEndPeriod") . '</td><td>';
  726. print dol_print_date($object->dateep, 'day');
  727. print '</td></tr>';
  728. }
  729. /*print "<tr>";
  730. print '<td>'.$langs->trans("DatePayment").'</td><td>';
  731. print dol_print_date($object->datep, 'day');
  732. print '</td></tr>';
  733. print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
  734. print dol_print_date($object->datev, 'day');
  735. print '</td></tr>';*/
  736. if ($action == 'edit') {
  737. print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
  738. } else {
  739. print '<tr><td>' . $langs->trans("Amount") . '</td><td><span class="amount">' . price($object->amount, 0, $langs, 1, -1, -1, $conf->currency) . '</span></td></tr>';
  740. }
  741. // Default mode of payment
  742. print '<tr><td>';
  743. print '<table class="nobordernopadding" width="100%"><tr><td>';
  744. print $langs->trans('DefaultPaymentMode');
  745. print '</td>';
  746. if ($action != 'editmode')
  747. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  748. print '</tr></table>';
  749. print '</td><td>';
  750. if ($action == 'editmode') {
  751. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
  752. } else {
  753. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
  754. }
  755. print '</td></tr>';
  756. // Default Bank Account
  757. if (!empty($conf->banque->enabled)) {
  758. print '<tr><td class="nowrap">';
  759. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  760. print $langs->trans('DefaultBankAccount');
  761. print '<td>';
  762. if ($action != 'editbankaccount' && $user->rights->salaries->write) {
  763. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  764. }
  765. print '</tr></table>';
  766. print '</td><td>';
  767. if ($action == 'editbankaccount') {
  768. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  769. } else {
  770. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  771. }
  772. print '</td>';
  773. print '</tr>';
  774. }
  775. // Other attributes
  776. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  777. print '</table>';
  778. print '</div>';
  779. print '<div class="fichehalfright">';
  780. $nbcols = 3;
  781. if (!empty($conf->banque->enabled)) {
  782. $nbcols++;
  783. }
  784. /*
  785. * Payments
  786. */
  787. $sql = "SELECT p.rowid, p.num_payment as num_payment, p.datep as dp, p.amount,";
  788. $sql .= " c.code as type_code,c.libelle as paiement_type,";
  789. $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
  790. $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
  791. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
  792. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
  793. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
  794. $sql .= ", ".MAIN_DB_PREFIX."salary as salaire";
  795. $sql .= " WHERE p.fk_salary = ".((int) $id);
  796. $sql .= " AND p.fk_salary = salaire.rowid";
  797. $sql .= " AND salaire.entity IN (".getEntity('tax').")";
  798. $sql .= " ORDER BY dp DESC";
  799. //print $sql;
  800. $resql = $db->query($sql);
  801. if ($resql) {
  802. $totalpaid = 0;
  803. $num = $db->num_rows($resql);
  804. $i = 0; $total = 0;
  805. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  806. print '<table class="noborder paymenttable">';
  807. print '<tr class="liste_titre">';
  808. print '<td>'.$langs->trans("RefPayment").'</td>';
  809. print '<td>'.$langs->trans("Date").'</td>';
  810. print '<td>'.$langs->trans("Type").'</td>';
  811. if (!empty($conf->banque->enabled)) {
  812. print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
  813. }
  814. print '<td class="right">'.$langs->trans("Amount").'</td>';
  815. print '</tr>';
  816. if ($num > 0) {
  817. $bankaccountstatic = new Account($db);
  818. while ($i < $num) {
  819. $objp = $db->fetch_object($resql);
  820. print '<tr class="oddeven"><td>';
  821. print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a></td>';
  822. print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  823. $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
  824. print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
  825. if (!empty($conf->banque->enabled)) {
  826. $bankaccountstatic->id = $objp->baid;
  827. $bankaccountstatic->ref = $objp->baref;
  828. $bankaccountstatic->label = $objp->baref;
  829. $bankaccountstatic->number = $objp->banumber;
  830. $bankaccountstatic->currency_code = $objp->bacurrency_code;
  831. if (!empty($conf->accounting->enabled)) {
  832. $bankaccountstatic->account_number = $objp->account_number;
  833. $accountingjournal = new AccountingJournal($db);
  834. $accountingjournal->fetch($objp->fk_accountancy_journal);
  835. $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  836. }
  837. print '<td class="right">';
  838. if ($bankaccountstatic->id)
  839. print $bankaccountstatic->getNomUrl(1, 'transactions');
  840. print '</td>';
  841. }
  842. print '<td class="right">'.price($objp->amount)."</td>\n";
  843. print "</tr>";
  844. $totalpaid += $objp->amount;
  845. $i++;
  846. }
  847. } else {
  848. print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  849. print '<td></td><td></td><td></td><td></td>';
  850. print '</tr>';
  851. }
  852. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
  853. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
  854. $resteapayer = $object->amount - $totalpaid;
  855. $cssforamountpaymentcomplete = 'amountpaymentcomplete';
  856. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
  857. print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
  858. print "</table>";
  859. print '</div>';
  860. $db->free($resql);
  861. } else {
  862. dol_print_error($db);
  863. }
  864. print '</div>';
  865. print '</div>';
  866. print '<div class="clearboth"></div>';
  867. print dol_get_fiche_end();
  868. if ($action == 'edit') {
  869. print $form->buttonsSaveCancel();
  870. print "</form>";
  871. }
  872. $resteapayer = price2num($resteapayer, 'MT');
  873. /*
  874. * Action bar
  875. */
  876. print '<div class="tabsAction">'."\n";
  877. if ($action != 'edit') {
  878. // Reopen
  879. if ($object->paye && $user->rights->salaries->write) {
  880. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
  881. }
  882. // Edit
  883. if ($object->paye == 0 && $user->rights->salaries->write) {
  884. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
  885. }
  886. // Emit payment
  887. if ($object->paye == 0 && ((price2num($object->amount) < 0 && $resteapayer < 0) || (price2num($object->amount) > 0 && $resteapayer > 0)) && $user->rights->salaries->write) {
  888. print dolGetButtonAction('', $langs->trans('DoPayment'), 'default', DOL_URL_ROOT.'/salaries/paiement_salary.php?action=create&token='.newToken().'&id='. $object->id, '');
  889. }
  890. // Classify 'paid'
  891. // If payment complete $resteapayer <= 0 on a positive salary, or if amount is negative, we allow to classify as paid.
  892. if ($object->paye == 0 && (($resteapayer <= 0 && $object->amount > 0) || ($object->amount <= 0)) && $user->rights->salaries->write) {
  893. print dolGetButtonAction('', $langs->trans('ClassifyPaid'), 'default', $_SERVER["PHP_SELF"].'?action=paid&token='.newToken().'&id='.$object->id, '');
  894. }
  895. // Clone
  896. if ($user->rights->salaries->write) {
  897. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id, '');
  898. }
  899. if (!empty($user->rights->salaries->delete) && empty($totalpaid)) {
  900. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
  901. } else {
  902. print dolGetButtonAction($langs->trans('DisabledBecausePayments'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
  903. }
  904. }
  905. print "</div>";
  906. // Select mail models is same action as presend
  907. if (GETPOST('modelselected')) {
  908. $action = 'presend';
  909. }
  910. if ($action != 'presend') {
  911. print '<div class="fichecenter"><div class="fichehalfleft">';
  912. print '<a name="builddoc"></a>'; // ancre
  913. $includedocgeneration = 1;
  914. // Documents
  915. if ($includedocgeneration) {
  916. $objref = dol_sanitizeFileName($object->ref);
  917. $relativepath = $objref.'/'.$objref.'.pdf';
  918. $filedir = $conf->salaries->dir_output.'/'.$objref;
  919. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  920. //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
  921. $genallowed = 0; // If you can read, you can build the PDF to read content
  922. $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
  923. print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  924. }
  925. // Show links to link elements
  926. /*
  927. $linktoelem = $form->showLinkToObjectBlock($object, null, array('salaries'));
  928. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  929. */
  930. print '</div><div class="fichehalfright">';
  931. $MAXEVENT = 10;
  932. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
  933. // List of actions on element
  934. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  935. $formactions = new FormActions($db);
  936. //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  937. print '</div></div>';
  938. }
  939. //Select mail models is same action as presend
  940. if (GETPOST('modelselected')) {
  941. $action = 'presend';
  942. }
  943. // Presend form
  944. $modelmail = 'salary';
  945. $defaulttopic = 'InformationMessage';
  946. $diroutput = $conf->salaries->dir_output;
  947. $trackid = 'salary'.$object->id;
  948. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  949. }
  950. // End of page
  951. llxFooter();
  952. $db->close();