card.php 43 KB

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