voucherhistory_card.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. $res = 0;
  3. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  4. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  5. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  6. }
  7. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  8. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  9. $tmp2 = realpath(__FILE__);
  10. $i = strlen($tmp) - 1;
  11. $j = strlen($tmp2) - 1;
  12. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  13. $i--;
  14. $j--;
  15. }
  16. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  17. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  18. }
  19. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  20. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  21. }
  22. // Try main.inc.php using relative path
  23. if (!$res && file_exists("../main.inc.php")) {
  24. $res = @include "../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../main.inc.php")) {
  27. $res = @include "../../main.inc.php";
  28. }
  29. if (!$res && file_exists("../../../main.inc.php")) {
  30. $res = @include "../../../main.inc.php";
  31. }
  32. if (!$res) {
  33. die("Include of main fails");
  34. }
  35. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  38. require_once DOL_DOCUMENT_ROOT . '/custom/voucher/class/helper.class.php';
  39. require_once DOL_DOCUMENT_ROOT . '/custom/voucher/class/voucherhistory.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/printPDF_szisz.php';
  42. require_once DOL_DOCUMENT_ROOT . '/core/lib/pdf.lib.php';
  43. dol_include_once('/voucher/class/voucherhistory.class.php');
  44. dol_include_once('/voucher/lib/voucher_voucherhistory.lib.php');
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("voucher@voucher", "other"));
  47. // Get parameters
  48. $id = GETPOST('id', 'int');
  49. $ref = GETPOST('ref', 'alpha');
  50. $lineid = GETPOST('lineid', 'int');
  51. $action = GETPOST('action', 'aZ09');
  52. $confirm = GETPOST('confirm', 'alpha');
  53. $cancel = GETPOST('cancel', 'aZ09');
  54. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search
  55. $backtopage = GETPOST('backtopage', 'alpha');
  56. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  57. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  58. $fk_product = GETPOST('fk_product', 'int');
  59. $eventId = GETPOST('eventId', 'int');
  60. //print_r($_REQUEST);exit;
  61. // Initialize technical objects
  62. $object = new Voucherhistory($db);
  63. $extrafields = new ExtraFields($db);
  64. $VoucherHelper = new VoucherHelper();
  65. $diroutputmassaction = $conf->voucher->dir_output . '/temp/massgeneration/' . $user->id;
  66. $hookmanager->initHooks(array('voucherhistorycard', 'globalcard')); // Note that conf->hooks_modules contains array
  67. // Fetch optionals attributes and labels
  68. $extrafields->fetch_name_optionals_label($object->table_element);
  69. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  70. // Initialize array of search criterias
  71. $search_all = GETPOST("search_all", 'alpha');
  72. $search = array();
  73. foreach ($object->fields as $key => $val) {
  74. if (GETPOST('search_' . $key, 'alpha')) {
  75. $search[$key] = GETPOST('search_' . $key, 'alpha');
  76. }
  77. }
  78. if (empty($action) && empty($id) && empty($ref)) {
  79. $action = 'view';
  80. }
  81. // Load object
  82. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  83. // There is several ways to check permission.
  84. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  85. $enablepermissioncheck = 0;
  86. if ($enablepermissioncheck) {
  87. $permissiontoread = $user->hasRight('voucher', 'voucherhistory', 'read');
  88. $permissiontoadd = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  89. $permissiontodelete = $user->hasRight('voucher', 'voucherhistory', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  90. $permissionnote = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_setnotes.inc.php
  91. $permissiondellink = $user->hasRight('voucher', 'voucherhistory', 'write'); // Used by the include of actions_dellink.inc.php
  92. } else {
  93. $permissiontoread = 1;
  94. $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  95. $permissiontodelete = 1;
  96. $permissionnote = 1;
  97. $permissiondellink = 1;
  98. }
  99. $upload_dir = $conf->voucher->multidir_output[isset($object->entity) ? $object->entity : 1] . '/voucherhistory';
  100. if (!isModEnabled("voucher")) {
  101. accessforbidden();
  102. }
  103. if (!$permissiontoread) {
  104. accessforbidden();
  105. }
  106. /*
  107. * Actions
  108. */
  109. $parameters = array();
  110. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  111. if ($reshook < 0) {
  112. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  113. }
  114. if (empty($reshook)) {
  115. $error = 0;
  116. $backurlforlist = dol_buildpath('/voucher/voucherhistory_list.php', 1);
  117. if (empty($backtopage) || ($cancel && empty($id))) {
  118. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  119. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  120. $backtopage = $backurlforlist;
  121. } else {
  122. $backtopage = dol_buildpath('/voucher/voucherhistory_card.php', 1) . '?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__');
  123. }
  124. }
  125. }
  126. $triggermodname = 'VOUCHER_VOUCHERHISTORY_MODIFY'; // Name of trigger action code to execute when we modify record
  127. /* if ($action == 'add') {
  128. # Search Product
  129. $productObj = new Product($db);
  130. $productResult = $productObj->fetch($product_id);
  131. # Search bundle
  132. # Create BBTicket
  133. $newticket = new BbTicket($db);
  134. $newticket->fk_facture = null;
  135. $newticket->bundle_id = $fk_product;
  136. $newticket->usable_occasions = $ticket->usable_occasions;
  137. $newticket->usage = $ticket->usage;
  138. $newticket->available_at = $ticket->available_at;
  139. $newticket->validated_at = $ticket->validated_at;
  140. $newticket->expire_at = $ticket->expire_at;
  141. $newticket->ticket_id = $ticket->ticket_id;
  142. $newticket->fk_settlements_group_id = $group_id;
  143. if ($newticket->create($this->user) == -1) {
  144. dol_syslog("Nem sikerult a ticketek mentese. facture_id: " . $object->fk_facture);
  145. }
  146. # Save VoucherHistory OBject
  147. $object->fk_bundle = $fk_product;
  148. $object->fk_product = $fk_product;
  149. $object->fk_event = $eventId;
  150. $object->fk_ticket = 100;
  151. $object->pdf_path = 'asd';
  152. $object->date_creation = dol_now();
  153. $object->status = "0";
  154. } */
  155. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  156. include DOL_DOCUMENT_ROOT . '/custom/voucher/core/actions_addupdatedelete.inc.php';
  157. //include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
  158. // Actions when linking object each other
  159. include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
  160. // Actions when printing a doc from card
  161. include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
  162. // Action to move up and down lines of object
  163. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  164. // Action to build doc
  165. include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
  166. if ($action == 'set_thirdparty' && $permissiontoadd) {
  167. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  168. }
  169. if ($action == 'classin' && $permissiontoadd) {
  170. $object->setProject(GETPOST('projectid', 'int'));
  171. }
  172. // Actions to send emails
  173. $triggersendname = 'VOUCHER_VOUCHERHISTORY_SENTBYMAIL';
  174. $autocopy = 'MAIN_MAIL_AUTOCOPY_VOUCHERHISTORY_TO';
  175. $trackid = 'voucherhistory' . $object->id;
  176. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  177. }
  178. /*
  179. * View
  180. *
  181. * Put here all code to build page
  182. */
  183. $form = new Form($db);
  184. $formfile = new FormFile($db);
  185. $formproject = new FormProjets($db);
  186. $title = $langs->trans("Voucherhistory");
  187. $help_url = '';
  188. llxHeader('', $title, $help_url);
  189. // Part to create
  190. if ($action == 'create') {
  191. if (empty($permissiontoadd)) {
  192. accessforbidden('NotEnoughPermissions', 0, 1);
  193. }
  194. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Voucherhistory")), '', 'object_' . $object->picto);
  195. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  196. print '<input type="hidden" name="token" value="' . newToken() . '">';
  197. print '<input type="hidden" name="action" value="add">';
  198. if ($backtopage) {
  199. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  200. }
  201. if ($backtopageforcancel) {
  202. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  203. }
  204. print dol_get_fiche_head(array(), '');
  205. // Set some default values
  206. //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
  207. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  208. // Common attributes
  209. include DOL_DOCUMENT_ROOT . '/custom/voucher/core/tpl/commonfields_add.tpl.php';
  210. //include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  211. // Other attributes
  212. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  213. print '</table>' . "\n";
  214. print dol_get_fiche_end();
  215. print $form->buttonsSaveCancel("Create");
  216. print '</form>';
  217. //dol_set_focus('input[name="ref"]');
  218. }
  219. // Part to edit record
  220. if (($id || $ref) && $action == 'edit') {
  221. print load_fiche_titre($langs->trans("Voucherhistory"), '', 'object_' . $object->picto);
  222. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  223. print '<input type="hidden" name="token" value="' . newToken() . '">';
  224. print '<input type="hidden" name="action" value="update">';
  225. print '<input type="hidden" name="id" value="' . $object->id . '">';
  226. if ($backtopage) {
  227. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  228. }
  229. if ($backtopageforcancel) {
  230. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  231. }
  232. print dol_get_fiche_head();
  233. print '<table class="border centpercent tableforfieldedit">' . "\n";
  234. // Common attributes
  235. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  236. // Other attributes
  237. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
  238. print '</table>';
  239. print dol_get_fiche_end();
  240. print $form->buttonsSaveCancel();
  241. print '</form>';
  242. }
  243. // Part to show record
  244. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  245. $head = voucherhistoryPrepareHead($object);
  246. print dol_get_fiche_head($head, 'card', $langs->trans("Voucherhistory"), -1, $object->picto);
  247. $formconfirm = '';
  248. // Confirmation to delete
  249. if ($action == 'delete') {
  250. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteVoucherhistory'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  251. }
  252. // Confirmation to delete line
  253. if ($action == 'deleteline') {
  254. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  255. }
  256. // Clone confirmation
  257. if ($action == 'clone') {
  258. // Create an array for form
  259. $formquestion = array();
  260. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  261. }
  262. // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
  263. if ($action == 'xxx') {
  264. $text = $langs->trans('ConfirmActionVoucherhistory', $object->ref);
  265. /*if (isModEnabled('notification'))
  266. {
  267. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  268. $notify = new Notify($db);
  269. $text .= '<br>';
  270. $text .= $notify->confirmMessage('VOUCHERHISTORY_CLOSE', $object->socid, $object);
  271. }*/
  272. $formquestion = array();
  273. /*
  274. $forcecombo=0;
  275. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  276. $formquestion = array(
  277. // 'text' => $langs->trans("ConfirmClone"),
  278. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  279. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  280. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  281. );
  282. */
  283. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  284. }
  285. // Call Hook formConfirm
  286. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  287. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  288. if (empty($reshook)) {
  289. $formconfirm .= $hookmanager->resPrint;
  290. } elseif ($reshook > 0) {
  291. $formconfirm = $hookmanager->resPrint;
  292. }
  293. // Print form confirm
  294. print $formconfirm;
  295. // Object card
  296. // ------------------------------------------------------------
  297. $linkback = '<a href="' . dol_buildpath('/voucher/voucherhistory_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  298. $morehtmlref = '<div class="refidno">';
  299. /*
  300. // Ref customer
  301. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
  302. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1);
  303. // Thirdparty
  304. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  305. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  306. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  307. }
  308. // Project
  309. if (isModEnabled('project')) {
  310. $langs->load("projects");
  311. $morehtmlref .= '<br>';
  312. if ($permissiontoadd) {
  313. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  314. if ($action != 'classify') {
  315. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  316. }
  317. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  318. } else {
  319. if (!empty($object->fk_project)) {
  320. $proj = new Project($db);
  321. $proj->fetch($object->fk_project);
  322. $morehtmlref .= $proj->getNomUrl(1);
  323. if ($proj->title) {
  324. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  325. }
  326. }
  327. }
  328. }
  329. */
  330. $morehtmlref .= '</div>';
  331. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  332. print '<div class="fichecenter">';
  333. print '<div class="fichehalfleft">';
  334. print '<div class="underbanner clearboth"></div>';
  335. print '<table class="border centpercent tableforfield">' . "\n";
  336. // Common attributes
  337. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  338. //unset($object->fields['fk_project']); // Hide field already shown in banner
  339. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  340. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  341. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  342. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  343. print '</table>';
  344. print '</div>';
  345. print '</div>';
  346. print '<div class="clearboth"></div>';
  347. print dol_get_fiche_end();
  348. /*
  349. * Lines
  350. */
  351. if (!empty($object->table_element_line)) {
  352. // Show object lines
  353. $result = $object->getLinesArray();
  354. print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
  355. <input type="hidden" name="token" value="' . newToken() . '">
  356. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
  357. <input type="hidden" name="mode" value="">
  358. <input type="hidden" name="page_y" value="">
  359. <input type="hidden" name="id" value="' . $object->id . '">
  360. ';
  361. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  362. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  363. }
  364. print '<div class="div-table-responsive-no-min">';
  365. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  366. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  367. }
  368. if (!empty($object->lines)) {
  369. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  370. }
  371. // Form to add new line
  372. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  373. if ($action != 'editline') {
  374. // Add products/services form
  375. $parameters = array();
  376. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  377. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  378. if (empty($reshook))
  379. $object->formAddObjectLine(1, $mysoc, $soc);
  380. }
  381. }
  382. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  383. print '</table>';
  384. }
  385. print '</div>';
  386. print "</form>\n";
  387. }
  388. // Buttons for actions
  389. if ($action != 'presend' && $action != 'editline') {
  390. print '<div class="tabsAction">' . "\n";
  391. $parameters = array();
  392. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  393. if ($reshook < 0) {
  394. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  395. }
  396. if (empty($reshook)) {
  397. // Send
  398. if (empty($user->socid)) {
  399. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&token=' . newToken() . '&mode=init#formmailbeforetitle');
  400. }
  401. // Back to draft
  402. if ($object->status == $object::STATUS_VALIDATED) {
  403. print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  404. }
  405. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
  406. // Validate
  407. if ($object->status == $object::STATUS_DRAFT) {
  408. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  409. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=confirm_validate&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  410. } else {
  411. $langs->load("errors");
  412. print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
  413. }
  414. }
  415. // Clone
  416. if ($permissiontoadd) {
  417. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . (!empty($object->socid) ? '&socid=' . $object->socid : '') . '&action=clone&token=' . newToken(), '', $permissiontoadd);
  418. }
  419. /*
  420. if ($permissiontoadd) {
  421. if ($object->status == $object::STATUS_ENABLED) {
  422. print dolGetButtonAction('', $langs->trans('Disable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable&token='.newToken(), '', $permissiontoadd);
  423. } else {
  424. print dolGetButtonAction('', $langs->trans('Enable'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken(), '', $permissiontoadd);
  425. }
  426. }
  427. if ($permissiontoadd) {
  428. if ($object->status == $object::STATUS_VALIDATED) {
  429. print dolGetButtonAction('', $langs->trans('Cancel'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontoadd);
  430. } else {
  431. print dolGetButtonAction('', $langs->trans('Re-Open'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
  432. }
  433. }
  434. */
  435. // Delete
  436. $params = array();
  437. print dolGetButtonAction('', $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=delete&token=' . newToken(), 'delete', $permissiontodelete, $params);
  438. }
  439. print '</div>' . "\n";
  440. }
  441. // Select mail models is same action as presend
  442. if (GETPOST('modelselected')) {
  443. $action = 'presend';
  444. }
  445. if ($action != 'presend') {
  446. print '<div class="fichecenter"><div class="fichehalfleft">';
  447. print '<a name="builddoc"></a>'; // ancre
  448. $includedocgeneration = 0;
  449. // Documents
  450. if ($includedocgeneration) {
  451. $objref = dol_sanitizeFileName($object->ref);
  452. $relativepath = $objref . '/' . $objref . '.pdf';
  453. $filedir = $conf->voucher->dir_output . '/' . $object->element . '/' . $objref;
  454. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  455. $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content
  456. $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card
  457. print $formfile->showdocuments('voucher:Voucherhistory', $object->element . '/' . $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  458. }
  459. // Show links to link elements
  460. $linktoelem = $form->showLinkToObjectBlock($object, null, array('voucherhistory'));
  461. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  462. print '</div><div class="fichehalfright">';
  463. $MAXEVENT = 10;
  464. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/voucher/voucherhistory_agenda.php', 1) . '?id=' . $object->id);
  465. // List of actions on element
  466. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  467. $formactions = new FormActions($db);
  468. $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  469. print '</div></div>';
  470. }
  471. //Select mail models is same action as presend
  472. if (GETPOST('modelselected')) {
  473. $action = 'presend';
  474. }
  475. // Presend form
  476. $modelmail = 'voucherhistory';
  477. $defaulttopic = 'InformationMessage';
  478. $diroutput = $conf->voucher->dir_output;
  479. $trackid = 'voucherhistory' . $object->id;
  480. include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
  481. }
  482. //print_r($_REQUEST);
  483. // End of page
  484. llxFooter();
  485. $db->close();
  486. echo '<link rel="stylesheet" type="text/css" href="' . dol_buildpath('/custom/voucher/css/voucher.css', 1) . '">';
  487. echo '<script type="text/javascript" src="' . dol_buildpath('/custom/voucher/scripts/voucher.js', 1) . '"></script>';