card.php 43 KB

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