summaryrefslogtreecommitdiff
path: root/bin/jc.pl
blob: d466a78f1e8697a78df04ffe939cf356ba92d971 (plain)
  1. #=====================================================================
  2. # LedgerSMB Small Medium Business Accounting
  3. # http://www.ledgersmb.org/
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (c) 2005
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. #
  22. #
  23. # This program is free software; you can redistribute it and/or modify
  24. # it under the terms of the GNU General Public License as published by
  25. # the Free Software Foundation; either version 2 of the License, or
  26. # (at your option) any later version.
  27. #
  28. # This program is distributed in the hope that it will be useful,
  29. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. # GNU General Public License for more details.
  32. # You should have received a copy of the GNU General Public License
  33. # along with this program; if not, write to the Free Software
  34. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35. #======================================================================
  36. #
  37. # Job Costing module
  38. #
  39. #======================================================================
  40. use LedgerSMB::JC;
  41. 1;
  42. # end of main
  43. sub add {
  44. if ( $form->{type} eq 'timecard' ) {
  45. $form->{title} = $locale->text('Add Time Card');
  46. }
  47. if ( $form->{type} eq 'storescard' ) {
  48. $form->{title} = $locale->text('Add Stores Card');
  49. }
  50. $form->{callback} =
  51. "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&sessionid=$form->{sessionid}&project=$form->{project}"
  52. unless $form->{callback};
  53. &{"prepare_$form->{type}"};
  54. $form->{orphaned} = 1;
  55. &display_form;
  56. }
  57. sub edit {
  58. if ( $form->{type} eq 'timecard' ) {
  59. $form->{title} = $locale->text('Edit Time Card');
  60. }
  61. if ( $form->{type} eq 'storescard' ) {
  62. $form->{title} = $locale->text('Add Stores Card');
  63. }
  64. &{"prepare_$form->{type}"};
  65. &display_form;
  66. }
  67. sub jcitems_links {
  68. if ( @{ $form->{all_project} } ) {
  69. $form->{selectprojectnumber} = "<option>\n";
  70. foreach $ref ( @{ $form->{all_project} } ) {
  71. $form->{selectprojectnumber} .=
  72. qq|<option value="$ref->{projectnumber}--$ref->{id}">$ref->{projectnumber}\n|;
  73. if ( $form->{projectnumber} eq "$ref->{projectnumber}--$ref->{id}" )
  74. {
  75. $form->{projectdescription} = $ref->{description};
  76. }
  77. }
  78. }
  79. else {
  80. if ( $form->{project} eq 'job' ) {
  81. $form->error( $locale->text('No open Jobs!') );
  82. }
  83. else {
  84. $form->error( $locale->text('No open Projects!') );
  85. }
  86. }
  87. if ( @{ $form->{all_parts} } ) {
  88. $form->{selectpartnumber} = "<option>\n";
  89. foreach $ref ( @{ $form->{all_parts} } ) {
  90. $form->{selectpartnumber} .=
  91. qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
  92. if ( $form->{partnumber} eq "$ref->{partnumber}--$ref->{id}" ) {
  93. if ( $form->{partnumber} ne $form->{oldpartnumber} ) {
  94. for (qw(description unit sellprice pricematrix)) {
  95. $form->{$_} = $ref->{$_};
  96. }
  97. }
  98. }
  99. }
  100. }
  101. else {
  102. if ( $form->{type} eq 'timecard' ) {
  103. if ( $form->{project} eq 'job' ) {
  104. $form->error( $locale->text('No Labor codes on file!') );
  105. }
  106. else {
  107. $form->error( $locale->text('No Services on file!') );
  108. }
  109. }
  110. else {
  111. $form->error( $locale->text('No Parts on file!') );
  112. }
  113. }
  114. # employees
  115. if ( @{ $form->{all_employee} } ) {
  116. $form->{selectemployee} = "<option>\n";
  117. for ( @{ $form->{all_employee} } ) {
  118. $form->{selectemployee} .=
  119. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  120. }
  121. }
  122. else {
  123. $form->error( $locale->text('No Employees on file!') );
  124. }
  125. }
  126. sub search {
  127. # accounting years
  128. $form->all_years( \%myconfig );
  129. if ( @{ $form->{all_years} } ) {
  130. $form->{selectaccountingyear} = "<option>\n";
  131. for ( @{ $form->{all_years} } ) {
  132. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  133. }
  134. $form->{selectaccountingmonth} = "<option>\n";
  135. for ( sort keys %{ $form->{all_month} } ) {
  136. $form->{selectaccountingmonth} .=
  137. qq|<option value=$_>|
  138. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  139. }
  140. $selectfrom = qq|
  141. <tr>
  142. <th align=right>| . $locale->text('Period') . qq|</th>
  143. <td colspan=3>
  144. <select name=month>$form->{selectaccountingmonth}</select>
  145. <select name=year>$form->{selectaccountingyear}</select>
  146. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  147. . $locale->text('Current') . qq|
  148. <input name=interval class=radio type=radio value=1>&nbsp;|
  149. . $locale->text('Month') . qq|
  150. <input name=interval class=radio type=radio value=3>&nbsp;|
  151. . $locale->text('Quarter') . qq|
  152. <input name=interval class=radio type=radio value=12>&nbsp;|
  153. . $locale->text('Year') . qq|
  154. </td>
  155. </tr>
  156. |;
  157. }
  158. $fromto = qq|
  159. <tr>
  160. <th align=right nowrap>| . $locale->text('Startdate') . qq|</th>
  161. <td>|
  162. . $locale->text('From')
  163. . qq| <input name=startdatefrom size=11 title="$myconfig{dateformat}">
  164. |
  165. . $locale->text('To')
  166. . qq| <input name=startdateto size=11 title="$myconfig{dateformat}"></td>
  167. </tr>
  168. $selectfrom
  169. |;
  170. if ( $form->{type} eq 'timecard' ) {
  171. $form->{title} = $locale->text('Time Cards');
  172. JC->jcitems_links( \%myconfig, \%$form );
  173. }
  174. if ( $form->{type} eq 'storescard' ) {
  175. $form->{title} = $locale->text('Stores Cards');
  176. JC->jcitems_links( \%myconfig, \%$form );
  177. }
  178. if ( @{ $form->{all_project} } ) {
  179. $form->{selectprojectnumber} = "<option>\n";
  180. for ( @{ $form->{all_project} } ) {
  181. $form->{selectprojectnumber} .=
  182. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  183. }
  184. }
  185. if ( @{ $form->{all_parts} } ) {
  186. $form->{selectpartnumber} = "<option>\n";
  187. foreach $ref ( @{ $form->{all_parts} } ) {
  188. $form->{selectpartnumber} .=
  189. qq|<option value="$ref->{partnumber}--$ref->{id}">$ref->{partnumber}\n|;
  190. }
  191. }
  192. if ( $form->{project} eq 'job' ) {
  193. $joblabel = $locale->text('Job Number');
  194. $laborlabel = $locale->text('Labor Code');
  195. }
  196. elsif ( $form->{project} eq 'project' ) {
  197. $joblabel = $locale->text('Project Number');
  198. $laborlabel = $locale->text('Service Code');
  199. }
  200. else {
  201. $joblabel = $locale->text('Project/Job Number');
  202. $laborlabel = $locale->text('Service/Labor Code');
  203. }
  204. if ( $form->{selectprojectnumber} ) {
  205. $jobnumber = qq|
  206. <tr>
  207. <th align=right nowrap>$joblabel</th>
  208. <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
  209. </tr>
  210. |;
  211. }
  212. if ( $form->{type} eq 'timecard' ) {
  213. # employees
  214. if ( @{ $form->{all_employee} } ) {
  215. $form->{selectemployee} = "<option>\n";
  216. for ( @{ $form->{all_employee} } ) {
  217. $form->{selectemployee} .=
  218. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  219. }
  220. }
  221. else {
  222. $form->error( $locale->text('No Employees on file!') );
  223. }
  224. if ( $form->{selectpartnumber} ) {
  225. $partnumber = qq|
  226. <tr>
  227. <th align=right nowrap>$laborlabel</th>
  228. <td colspan=3><select name=partnumber>$form->{selectpartnumber}</select></td>
  229. </tr>
  230. |;
  231. }
  232. $employee = qq|
  233. <tr>
  234. <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
  235. <td colspan=3><select name=employee>$form->{selectemployee}</select></td>
  236. </tr>
  237. |;
  238. $l_time =
  239. qq|<td nowrap><input name=l_time class=checkbox type=checkbox value=Y>&nbsp;|
  240. . $locale->text('Time')
  241. . qq|</td>|;
  242. }
  243. $form->header;
  244. print qq|
  245. <body>
  246. <form method=post action=$form->{script}>
  247. <table width=100%>
  248. <tr>
  249. <th class=listtop>$form->{title}</th>
  250. </tr>
  251. <tr height="5"></tr>
  252. <tr valign=top>
  253. <td>
  254. <table>
  255. $jobnumber
  256. $partnumber
  257. $employee
  258. $fromto
  259. <tr>
  260. <th align=right nowrap>| . $locale->text('Include in Report') . qq|</th>
  261. <td>
  262. <table>
  263. <tr>
  264. <td nowrap><input name=open class=checkbox type=checkbox value=Y checked> |
  265. . $locale->text('Open')
  266. . qq|</td>
  267. <td nowrap><input name=closed class=checkbox type=checkbox value=Y> |
  268. . $locale->text('Closed')
  269. . qq|</td>
  270. </tr>
  271. <tr>
  272. $l_time
  273. <td nowrap><input name=l_allocated class=checkbox type=checkbox value=Y> |
  274. . $locale->text('Allocated')
  275. . qq|</td>
  276. </tr>
  277. <tr>
  278. <td><input name=l_subtotal class=checkbox type=checkbox value=Y>&nbsp;|
  279. . $locale->text('Subtotal')
  280. . qq|</td>
  281. </tr>
  282. </table>
  283. </td>
  284. </tr>
  285. </table>
  286. </td>
  287. </tr>
  288. <tr>
  289. <td><hr size=3 noshade></td>
  290. </tr>
  291. </table>
  292. <input type=hidden name=nextsub value="list_$form->{type}">
  293. <input type=hidden name=sort value="transdate">
  294. |;
  295. $form->hide_form(qw(db path login sessionid project type));
  296. print qq|
  297. <br>
  298. <button type="submit" class="submit" name="action" value="continue">|
  299. . $locale->text('Continue')
  300. . qq|</button>
  301. </form>
  302. |;
  303. if ( $form->{lynx} ) {
  304. require "bin/menu.pl";
  305. &menubar;
  306. }
  307. print qq|
  308. </body>
  309. </html>
  310. |;
  311. }
  312. sub display_form {
  313. &{"$form->{type}_header"};
  314. &{"$form->{type}_footer"};
  315. }
  316. sub form_header {
  317. &{"$form->{type}_header"};
  318. }
  319. sub form_footer {
  320. &{"form->{type}_footer"};
  321. }
  322. sub prepare_timecard {
  323. $form->{formname} = "timecard";
  324. $form->{format} = "postscript" if $myconfig{printer};
  325. $form->{media} = $myconfig{printer};
  326. JC->get_jcitems( \%myconfig, \%$form );
  327. $form->{selectformname} =
  328. qq|<option value="timecard">| . $locale->text('Time Card');
  329. foreach $item (qw(in out)) {
  330. ( $form->{"${item}hour"}, $form->{"${item}min"}, $form->{"${item}sec"} )
  331. = split /:/, $form->{"checked$item"};
  332. for (qw(hour min sec)) {
  333. if ( ( $form->{"$item$_"} *= 1 ) > 0 ) {
  334. $form->{"$item$_"} = substr( qq|0$form->{"$item$_"}|, -2 );
  335. }
  336. else {
  337. $form->{"$item$_"} ||= "";
  338. }
  339. }
  340. }
  341. $form->{checkedin} =
  342. $form->{inhour} * 3600 + $form->{inmin} * 60 + $form->{insec};
  343. $form->{checkedout} =
  344. $form->{outhour} * 3600 + $form->{outmin} * 60 + $form->{outsec};
  345. if ( $form->{checkedin} > $form->{checkedout} ) {
  346. $form->{checkedout} =
  347. 86400 - ( $form->{checkedin} - $form->{checkedout} );
  348. $form->{checkedin} = 0;
  349. }
  350. $form->{clocked} = ( $form->{checkedout} - $form->{checkedin} ) / 3600;
  351. if ( $form->{clocked} ) {
  352. $form->{oldnoncharge} = $form->{clocked} - $form->{qty};
  353. }
  354. $form->{oldqty} = $form->{qty};
  355. $form->{noncharge} =
  356. $form->format_amount( \%myconfig, $form->{clocked} - $form->{qty}, 4 )
  357. if $form->{checkedin} != $form->{checkedout};
  358. $form->{clocked} = $form->format_amount( \%myconfig, $form->{clocked}, 4 );
  359. $form->{amount} = $form->{sellprice} * $form->{qty};
  360. for (qw(sellprice amount)) {
  361. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  362. }
  363. $form->{qty} = $form->format_amount( \%myconfig, $form->{qty}, 4 );
  364. $form->{allocated} = $form->format_amount( \%myconfig, $form->{allocated} );
  365. $form->{employee} .= "--$form->{employee_id}";
  366. $form->{projectnumber} .= "--$form->{project_id}";
  367. $form->{partnumber} .= "--$form->{parts_id}";
  368. $form->{oldpartnumber} = $form->{partnumber};
  369. if ( @{ $form->{all_language} } ) {
  370. $form->{selectlanguage} = "<option>\n";
  371. for ( @{ $form->{all_language} } ) {
  372. $form->{selectlanguage} .=
  373. qq|<option value="$_->{code}">$_->{description}\n|;
  374. }
  375. }
  376. &jcitems_links;
  377. $form->{locked} =
  378. ( $form->{revtrans} )
  379. ? '1'
  380. : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
  381. $form->datetonum( \%myconfig, $form->{closedto} ) );
  382. $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
  383. if ( $form->{income_accno_id} ) {
  384. $form->{locked} = 1 if $form->{production} == $form->{completed};
  385. }
  386. }
  387. sub timecard_header {
  388. # set option selected
  389. for (qw(employee projectnumber partnumber)) {
  390. $form->{"select$_"} =~ s/ selected//;
  391. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  392. }
  393. $rows = $form->numtextrows( $form->{description}, 50, 8 );
  394. for (qw(transdate checkedin checkedout partnumber)) {
  395. $form->{"old$_"} = $form->{$_};
  396. }
  397. for (qw(partnumber description)) {
  398. $form->{$_} = $form->quote( $form->{$_} );
  399. }
  400. if ( $rows > 1 ) {
  401. $description =
  402. qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
  403. }
  404. else {
  405. $description =
  406. qq|<input name=description size=48 value="$form->{description}">|;
  407. }
  408. if ( $form->{project} eq 'job' ) {
  409. $projectlabel = $locale->text('Job Number');
  410. $laborlabel = $locale->text('Labor Code');
  411. $rate = qq|<input type=hidden name=sellprice value=$form->{sellprice}>|;
  412. }
  413. else {
  414. if ( $form->{project} eq 'project' ) {
  415. $projectlabel = $locale->text('Project Number');
  416. $laborlabel = $locale->text('Service Code');
  417. }
  418. else {
  419. $projectlabel = $locale->text('Project/Job Number');
  420. $laborlabel = $locale->text('Service/Labor Code');
  421. }
  422. if ( $myconfig{role} ne 'user' ) {
  423. $rate = qq|
  424. <tr>
  425. <th align=right nowrap>| . $locale->text('Chargeout Rate') . qq|</th>
  426. <td><input name=sellprice value=$form->{sellprice}></td>
  427. <th align=right nowrap>| . $locale->text('Total') . qq|</th>
  428. <td>$form->{amount}</td>
  429. </tr>
  430. <tr>
  431. <th align=right nowrap>| . $locale->text('Allocated') . qq|</th>
  432. <td><input name=allocated value=$form->{allocated}></td>
  433. </tr>
  434. |;
  435. }
  436. else {
  437. $rate = qq|
  438. <tr>
  439. <th align=right nowrap>| . $locale->text('Chargeout Rate') . qq|</th>
  440. <td>$form->{sellprice}</td>
  441. <th align=right nowrap>| . $locale->text('Total') . qq|</th>
  442. <td>$form->{amount}</td>
  443. </tr>
  444. <tr>
  445. <th align=right nowrap>| . $locale->text('Allocated') . qq|</th>
  446. <td>$form->{allocated}</td>
  447. </tr>
  448. <input type=hidden name=sellprice value=$form->{sellprice}>
  449. <input type=hidden name=allocated value=$form->{allocated}>
  450. |;
  451. }
  452. }
  453. if ( $myconfig{role} eq 'user' ) {
  454. $charge =
  455. qq|<input type=hidden name=qty value=$form->{qty}>$form->{qty}|;
  456. }
  457. else {
  458. $charge = qq|<input name=qty value=$form->{qty}>|;
  459. }
  460. if ( ( $rows = $form->numtextrows( $form->{notes}, 40, 6 ) ) < 2 ) {
  461. $rows = 2;
  462. }
  463. $notes = qq|<tr>
  464. <th align=right>| . $locale->text('Notes') . qq|</th>
  465. <td colspan=3><textarea name="notes" rows=$rows cols=46 wrap=soft>$form->{notes}</textarea>
  466. </td>
  467. </tr>
  468. |;
  469. ##################
  470. ( $null, $form->{oldproject_id} ) = split /--/, $form->{projectnumber};
  471. $form->header;
  472. print qq|
  473. <body>
  474. <form method=post action="$form->{script}">
  475. |;
  476. $form->hide_form(
  477. qw(id type media format printed queued title closedto locked oldtransdate oldcheckedin oldcheckedout oldpartnumber project oldqty oldnoncharge pricematrix oldproject_id)
  478. );
  479. print qq|
  480. <table width=100%>
  481. <tr class=listtop>
  482. <th class=listtop>$form->{title}</th>
  483. </tr>
  484. <tr height="5"></tr>
  485. <tr>
  486. <td>
  487. <table>
  488. <tr>
  489. <td>
  490. <table>
  491. <tr>
  492. <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
  493. <td><select name=employee>$form->{selectemployee}</select></td>
  494. </tr>
  495. <tr>
  496. <th align=right nowrap>$projectlabel</th>
  497. <td><select name=projectnumber>$form->{selectprojectnumber}</select>
  498. </td>
  499. <td></td>
  500. <td>$form->{projectdescription}</td>
  501. <input type=hidden name=projectdescription value="|
  502. . $form->quote( $form->{projectdescription} ) . qq|">
  503. </tr>
  504. <tr>
  505. <th align=right nowrap>| . $locale->text('Date worked') . qq|</th>
  506. <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  507. </tr>
  508. <tr>
  509. <th align=right nowrap>$laborlabel</th>
  510. <td><select name=partnumber>$form->{selectpartnumber}</select></td>
  511. </tr>
  512. <tr valign=top>
  513. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  514. <td colspan=3>$description</td>
  515. </tr>
  516. <tr>
  517. <th align=right nowrap>| . $locale->text('Time In') . qq|</th>
  518. <td>
  519. <table>
  520. <tr>
  521. <td><input name=inhour title="hh" size=3 maxlength=2 value=$form->{inhour}></td>
  522. <td><input name=inmin title="mm" size=3 maxlength=2 value=$form->{inmin}></td>
  523. <td><input name=insec title="ss" size=3 maxlength=2 value=$form->{insec}></td>
  524. </tr>
  525. </table>
  526. </td>
  527. <th align=right nowrap>| . $locale->text('Time Out') . qq|</th>
  528. <td>
  529. <table>
  530. <tr>
  531. <td><input name=outhour title="hh" size=3 maxlength=2 value=$form->{outhour}></td>
  532. <td><input name=outmin title="mm" size=3 maxlength=2 value=$form->{outmin}></td>
  533. <td><input name=outsec title="ss" size=3 maxlength=2 value=$form->{outsec}></td>
  534. </tr>
  535. </table>
  536. </td>
  537. </tr>
  538. <tr>
  539. <th align=right nowrap>| . $locale->text('Clocked') . qq|</th>
  540. <td>$form->{clocked}</td>
  541. </tr>
  542. <tr>
  543. <th align=right nowrap>| . $locale->text('Non-chargeable') . qq|</th>
  544. <td><input name=noncharge value=$form->{noncharge}></td>
  545. </tr>
  546. <tr>
  547. <th align=right nowrap>| . $locale->text('Chargeable') . qq|</th>
  548. <td>$charge</td>
  549. </tr>
  550. $rate
  551. $notes
  552. </table>
  553. </td>
  554. </tr>
  555. |;
  556. }
  557. sub timecard_footer {
  558. print qq|
  559. </table>
  560. </td>
  561. </tr>
  562. <tr>
  563. <td><hr size=3 noshade></td>
  564. </tr>
  565. <tr>
  566. <td>
  567. |;
  568. &print_options;
  569. print qq|
  570. </td>
  571. </tr>
  572. </table>
  573. <br>
  574. |;
  575. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  576. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  577. if ( !$form->{readonly} ) {
  578. # type=submit $locale->text('Update')
  579. # type=submit $locale->text('Print')
  580. # type=submit $locale->text('Save')
  581. # type=submit $locale->text('Print and Save')
  582. # type=submit $locale->text('Save as new')
  583. # type=submit $locale->text('Print and Save as new')
  584. # type=submit $locale->text('Delete')
  585. %button = (
  586. 'update' =>
  587. { ndx => 1, key => 'U', value => $locale->text('Update') },
  588. 'print' =>
  589. { ndx => 2, key => 'P', value => $locale->text('Print') },
  590. 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  591. 'print_and_save' => {
  592. ndx => 6,
  593. key => 'R',
  594. value => $locale->text('Print and Save')
  595. },
  596. 'save_as_new' =>
  597. { ndx => 7, key => 'N', value => $locale->text('Save as new') },
  598. 'print_and_save_as_new' => {
  599. ndx => 8,
  600. key => 'W',
  601. value => $locale->text('Print and Save as new')
  602. },
  603. 'delete' =>
  604. { ndx => 16, key => 'D', value => $locale->text('Delete') },
  605. );
  606. %a = ();
  607. if ( $form->{id} ) {
  608. if ( !$form->{locked} ) {
  609. for ( 'update', 'print', 'save', 'save_as_new' ) { $a{$_} = 1 }
  610. if ( ${LedgerSMB::Sysconfig::latex} ) {
  611. for ( 'print_and_save', 'print_and_save_as_new' ) {
  612. $a{$_} = 1;
  613. }
  614. }
  615. if ( $form->{orphaned} ) {
  616. $a{'delete'} = 1;
  617. }
  618. }
  619. }
  620. else {
  621. if ( $transdate > $closedto ) {
  622. for ( 'update', 'print', 'save' ) { $a{$_} = 1 }
  623. if ( ${LedgerSMB::Sysconfig::latex} ) {
  624. $a{'print_and_save'} = 1;
  625. }
  626. }
  627. }
  628. }
  629. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  630. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  631. $form->print_button( \%button, $_ );
  632. }
  633. if ( $form->{lynx} ) {
  634. require "bin/menu.pl";
  635. &menubar;
  636. }
  637. $form->hide_form(qw(callback path login sessionid));
  638. print qq|
  639. </form>
  640. </body>
  641. </html>
  642. |;
  643. }
  644. sub prepare_storescard {
  645. $form->{formname} = "storescard";
  646. $form->{format} = "postscript" if $myconfig{printer};
  647. $form->{media} = $myconfig{printer};
  648. JC->get_jcitems( \%myconfig, \%$form );
  649. $form->{selectformname} =
  650. qq|<option value="storescard">| . $locale->text('Stores Card');
  651. $form->{amount} = $form->{sellprice} * $form->{qty};
  652. for (qw(sellprice amount)) {
  653. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  654. }
  655. $form->{qty} = $form->format_amount( \%myconfig, $form->{qty}, 4 );
  656. $form->{employee} .= "--$form->{employee_id}";
  657. $form->{projectnumber} .= "--$form->{project_id}";
  658. $form->{partnumber} .= "--$form->{parts_id}";
  659. $form->{oldpartnumber} = $form->{partnumber};
  660. if ( @{ $form->{all_language} } ) {
  661. $form->{selectlanguage} = "<option>\n";
  662. for ( @{ $form->{all_language} } ) {
  663. $form->{selectlanguage} .=
  664. qq|<option value="$_->{code}">$_->{description}\n|;
  665. }
  666. }
  667. &jcitems_links;
  668. $form->{locked} =
  669. ( $form->{revtrans} )
  670. ? '1'
  671. : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
  672. $form->datetonum( \%myconfig, $form->{closedto} ) );
  673. $form->{readonly} = 1 if $myconfig{acs} =~ /Production--Add Time Card/;
  674. if ( $form->{income_accno_id} ) {
  675. $form->{locked} = 1 if $form->{production} == $form->{completed};
  676. }
  677. }
  678. sub storescard_header {
  679. # set option selected
  680. for (qw(employee projectnumber partnumber)) {
  681. $form->{"select$_"} =~ s/ selected//;
  682. $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
  683. }
  684. $rows = $form->numtextrows( $form->{description}, 50, 8 );
  685. for (qw(transdate partnumber)) { $form->{"old$_"} = $form->{$_} }
  686. for (qw(partnumber description)) {
  687. $form->{$_} = $form->quote( $form->{$_} );
  688. }
  689. if ( $rows > 1 ) {
  690. $description =
  691. qq|<textarea name=description rows=$rows cols=46 wrap=soft>$form->{description}</textarea>|;
  692. }
  693. else {
  694. $description =
  695. qq|<input name=description size=48 value="$form->{description}">|;
  696. }
  697. $form->header;
  698. print qq|
  699. <body>
  700. <form method=post action="$form->{script}">
  701. |;
  702. $form->hide_form(
  703. qw(id type media format printed queued title closedto locked oldtransdate oldpartnumber project)
  704. );
  705. print qq|
  706. <table width=100%>
  707. <tr class=listtop>
  708. <th class=listtop>$form->{title}</th>
  709. </tr>
  710. <tr height="5"></tr>
  711. <tr>
  712. <td>
  713. <table>
  714. <tr>
  715. <td>
  716. <table>
  717. <tr>
  718. <th align=right nowrap>| . $locale->text('Job Number') . qq|</th>
  719. <td><select name=projectnumber>$form->{selectprojectnumber}</select>
  720. </td>
  721. <td>$form->{projectdescription}</td>
  722. <input type=hidden name=projectdescription value="|
  723. . $form->quote( $form->{projectdescription} ) . qq|">
  724. </tr>
  725. <tr>
  726. <th align=right nowrap>| . $locale->text('Date') . qq|</th>
  727. <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
  728. </tr>
  729. <tr>
  730. <th align=right nowrap>| . $locale->text('Part Number') . qq|</th>
  731. <td><select name=partnumber>$form->{selectpartnumber}</td>
  732. </tr>
  733. <tr valign=top>
  734. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  735. <td>$description</td>
  736. </tr>
  737. <tr>
  738. <th align=right nowrap>| . $locale->text('Qty') . qq|</th>
  739. <td><input name=qty size=6 value=$form->{qty}>
  740. <b>| . $locale->text('Cost') . qq|</b>
  741. <input name=sellprice size=10 value=$form->{sellprice}></td>
  742. </tr>
  743. <tr>
  744. <th align=right nowrap>| . $locale->text('Total') . qq|</th>
  745. <td>$form->{amount}</td>
  746. </tr>
  747. </table>
  748. </td>
  749. </tr>
  750. |;
  751. }
  752. sub storescard_footer {
  753. print qq|
  754. </table>
  755. </td>
  756. </tr>
  757. <tr>
  758. <td><hr size=3 noshade></td>
  759. </tr>
  760. <tr>
  761. <td>
  762. |;
  763. &print_options;
  764. print qq|
  765. </td>
  766. </tr>
  767. </table>
  768. <br>
  769. |;
  770. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  771. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  772. # type=submit $locale->text('Update')
  773. # type=submit $locale->text('Print')
  774. # type=submit $locale->text('Save')
  775. # type=submit $locale->text('Print and Save')
  776. # type=submit $locale->text('Save as new')
  777. # type=submit $locale->text('Print and Save as new')
  778. # type=submit $locale->text('Delete')
  779. if ( !$form->{readonly} ) {
  780. %button = (
  781. 'update' =>
  782. { ndx => 1, key => 'U', value => $locale->text('Update') },
  783. 'print' =>
  784. { ndx => 2, key => 'P', value => $locale->text('Print') },
  785. 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  786. 'print_and_save' => {
  787. ndx => 6,
  788. key => 'R',
  789. value => $locale->text('Print and Save')
  790. },
  791. 'save_as_new' =>
  792. { ndx => 7, key => 'N', value => $locale->text('Save as new') },
  793. 'print_and_save_as_new' => {
  794. ndx => 8,
  795. key => 'W',
  796. value => $locale->text('Print and Save as new')
  797. },
  798. 'delete' =>
  799. { ndx => 16, key => 'D', value => $locale->text('Delete') },
  800. );
  801. %a = ();
  802. if ( $form->{id} ) {
  803. if ( !$form->{locked} ) {
  804. for ( 'update', 'print', 'save', 'save_as_new' ) { $a{$_} = 1 }
  805. if ( ${LedgerSMB::Sysconfig::latex} ) {
  806. for ( 'print_and_save', 'print_and_save_as_new' ) {
  807. $a{$_} = 1;
  808. }
  809. }
  810. if ( $form->{orphaned} ) {
  811. $a{'delete'} = 1;
  812. }
  813. }
  814. }
  815. else {
  816. if ( $transdate > $closedto ) {
  817. for ( 'update', 'print', 'save' ) { $a{$_} = 1 }
  818. if ( ${LedgerSMB::Sysconfig::latex} ) {
  819. $a{'print_and_save'} = 1;
  820. }
  821. }
  822. }
  823. for ( keys %button ) { delete $button{$_} if !$a{$_} }
  824. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button )
  825. {
  826. $form->print_button( \%button, $_ );
  827. }
  828. }
  829. if ( $form->{lynx} ) {
  830. require "bin/menu.pl";
  831. &menubar;
  832. }
  833. $form->hide_form(qw(callback path login sessionid));
  834. print qq|
  835. </form>
  836. </body>
  837. </html>
  838. |;
  839. }
  840. sub update {
  841. ( $null, $form->{project_id} ) = split /--/, $form->{projectnumber};
  842. # check labor/part
  843. JC->jcitems_links( \%myconfig, \%$form );
  844. &jcitems_links;
  845. $checkmatrix = 1 if $form->{oldproject_id} != $form->{project_id};
  846. if ( $form->{type} eq 'timecard' ) {
  847. # time clocked
  848. %hour = ( in => 0, out => 0 );
  849. for $t (qw(in out)) {
  850. if ( $form->{"${t}sec"} > 60 ) {
  851. $form->{"${t}sec"} -= 60;
  852. $form->{"${t}min"}++;
  853. }
  854. if ( $form->{"${t}min"} > 60 ) {
  855. $form->{"${t}min"} -= 60;
  856. $form->{"${t}hour"}++;
  857. }
  858. $hour{$t} = $form->{"${t}hour"};
  859. }
  860. $form->{checkedin} =
  861. $hour{in} * 3600 + $form->{inmin} * 60 + $form->{insec};
  862. $form->{checkedout} =
  863. $hour{out} * 3600 + $form->{outmin} * 60 + $form->{outsec};
  864. if ( $form->{checkedin} > $form->{checkedout} ) {
  865. $form->{checkedout} =
  866. 86400 - ( $form->{checkedin} - $form->{checkedout} );
  867. $form->{checkedin} = 0;
  868. }
  869. $form->{clocked} = ( $form->{checkedout} - $form->{checkedin} ) / 3600;
  870. for (qw(sellprice qty noncharge allocated)) {
  871. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  872. }
  873. $checkmatrix = 1 if $form->{oldqty} != $form->{qty};
  874. if ( ( $form->{oldcheckedin} != $form->{checkedin} )
  875. || ( $form->{oldcheckedout} != $form->{checkedout} ) )
  876. {
  877. $checkmatrix = 1;
  878. $form->{oldqty} = $form->{qty} =
  879. $form->{clocked} - $form->{noncharge};
  880. $form->{oldnoncharge} = $form->{noncharge};
  881. }
  882. if ( ( $form->{qty} != $form->{oldqty} ) && $form->{clocked} ) {
  883. $form->{oldnoncharge} = $form->{noncharge} =
  884. $form->{clocked} - $form->{qty};
  885. $checkmatrix = 1;
  886. }
  887. if ( ( $form->{oldnoncharge} != $form->{noncharge} )
  888. && $form->{clocked} )
  889. {
  890. $form->{oldqty} = $form->{qty} =
  891. $form->{clocked} - $form->{noncharge};
  892. $checkmatrix = 1;
  893. }
  894. if ($checkmatrix) {
  895. @a = split / /, $form->{pricematrix};
  896. if ( scalar @a > 2 ) {
  897. for (@a) {
  898. ( $q, $p ) = split /:/, $_;
  899. if ( ( $p * 1 ) && ( $form->{qty} >= ( $q * 1 ) ) ) {
  900. $form->{sellprice} = $p;
  901. }
  902. }
  903. }
  904. }
  905. $form->{amount} = $form->{sellprice} * $form->{qty};
  906. $form->{clocked} =
  907. $form->format_amount( \%myconfig, $form->{clocked}, 4 );
  908. for (qw(sellprice amount)) {
  909. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  910. }
  911. for (qw(qty noncharge)) {
  912. $form->{"old$_"} = $form->{$_};
  913. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 4 );
  914. }
  915. }
  916. else {
  917. for (qw(sellprice qty allocated)) {
  918. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  919. }
  920. if ( $form->{oldqty} != $form->{qty} ) {
  921. @a = split / /, $form->{pricematrix};
  922. if ( scalar @a > 2 ) {
  923. for (@a) {
  924. ( $q, $p ) = split /:/, $_;
  925. if ( ( $p * 1 ) && ( $form->{qty} >= ( $q * 1 ) ) ) {
  926. $form->{sellprice} = $p;
  927. }
  928. }
  929. }
  930. }
  931. $form->{amount} = $form->{sellprice} * $form->{qty};
  932. for (qw(sellprice amount)) {
  933. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  934. }
  935. }
  936. $form->{allocated} = $form->format_amount( \%myconfig, $form->{allocated} );
  937. &display_form;
  938. }
  939. sub save {
  940. $form->isblank( "transdate", $locale->text('Date missing!') );
  941. if ( $form->{project} eq 'project' ) {
  942. $form->isblank( "projectnumber",
  943. $locale->text('Project Number missing!') );
  944. $form->isblank( "partnumber", $locale->text('Service Code missing!') );
  945. }
  946. else {
  947. $form->isblank( "projectnumber", $locale->text('Job Number missing!') );
  948. $form->isblank( "partnumber", $locale->text('Labor Code missing!') );
  949. }
  950. $closedto = $form->datetonum( \%myconfig, $form->{closedto} );
  951. $transdate = $form->datetonum( \%myconfig, $form->{transdate} );
  952. $msg =
  953. ( $form->{type} eq 'timecard' )
  954. ? $locale->text('Cannot save time card for a closed period!')
  955. : $locale->text('Cannot save stores card for a closed period!');
  956. $form->error($msg) if ( $transdate <= $closedto );
  957. if ( !$form->{resave} ) {
  958. if ( $form->{id} ) {
  959. &resave;
  960. exit;
  961. }
  962. }
  963. $rc = JC->save( \%myconfig, \%$form );
  964. if ( $form->{type} eq 'timecard' ) {
  965. $form->error(
  966. $locale->text('Cannot change time card for a completed job!') )
  967. if ( $rc == -1 );
  968. $form->error(
  969. $locale->text('Cannot add time card for a completed job!') )
  970. if ( $rc == -2 );
  971. if ($rc) {
  972. $form->redirect( $locale->text('Time Card saved!') );
  973. }
  974. else {
  975. $form->error( $locale->text('Cannot save time card!') );
  976. }
  977. }
  978. else {
  979. $form->error(
  980. $locale->text('Cannot change stores card for a completed job!') )
  981. if ( $rc == -1 );
  982. $form->error(
  983. $locale->text('Cannot add stores card for a completed job!') )
  984. if ( $rc == -2 );
  985. if ($rc) {
  986. $form->redirect( $locale->text('Stores Card saved!') );
  987. }
  988. else {
  989. $form->error( $locale->text('Cannot save stores card!') );
  990. }
  991. }
  992. }
  993. sub save_as_new {
  994. delete $form->{id};
  995. &save;
  996. }
  997. sub print_and_save_as_new {
  998. delete $form->{id};
  999. &print_and_save;
  1000. }
  1001. sub resave {
  1002. if ( $form->{print_and_save} ) {
  1003. $form->{nextsub} = "print_and_save";
  1004. $msg =
  1005. $locale->text('You are printing and saving an existing transaction!');
  1006. }
  1007. else {
  1008. $form->{nextsub} = "save";
  1009. $msg = $locale->text('You are saving an existing transaction!');
  1010. }
  1011. $form->{resave} = 1;
  1012. $form->header;
  1013. print qq|
  1014. <body>
  1015. <form method=post action=$form->{script}>
  1016. |;
  1017. delete $form->{action};
  1018. $form->hide_form;
  1019. print qq|
  1020. <h2 class=confirm>| . $locale->text('Warning!') . qq|</h2>
  1021. <h4>$msg</h4>
  1022. <button name="action" class="submit" type="submit" value="continue">|
  1023. . $locale->text('Continue')
  1024. . qq|</button>
  1025. </form>
  1026. </body>
  1027. </html>
  1028. |;
  1029. }
  1030. sub print_and_save {
  1031. $form->error( $locale->text('Select postscript or PDF!') )
  1032. if $form->{format} !~ /(postscript|pdf)/;
  1033. $form->error( $locale->text('Select a Printer!') )
  1034. if $form->{media} eq 'screen';
  1035. if ( !$form->{resave} ) {
  1036. if ( $form->{id} ) {
  1037. $form->{print_and_save} = 1;
  1038. &resave;
  1039. exit;
  1040. }
  1041. }
  1042. $old_form = new Form;
  1043. $form->{display_form} = "save";
  1044. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  1045. &{"print_$form->{formname}"}($old_form);
  1046. }
  1047. sub delete_timecard {
  1048. $form->header;
  1049. $employee = $form->{employee};
  1050. $employee =~ s/--.*//g;
  1051. $projectnumber = $form->{projectnumber};
  1052. $projectnumber =~ s/--.*//g;
  1053. print qq|
  1054. <body>
  1055. <form method=post action=$form->{script}>
  1056. |;
  1057. delete $form->{action};
  1058. $form->hide_form;
  1059. print qq|
  1060. <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
  1061. <h4>| . $locale->text('Are you sure you want to delete time card for') . qq|
  1062. <p>$form->{transdate}
  1063. <br>$employee
  1064. <br>$projectnumber
  1065. </h4>
  1066. <p>
  1067. <button name="action" class="submit" type="submit" value="yes">|
  1068. . $locale->text('Yes')
  1069. . qq|</button>
  1070. </form>
  1071. |;
  1072. }
  1073. sub delete { &{"delete_$form->{type}"} }
  1074. sub yes { &{"yes_delete_$form->{type}"} }
  1075. sub yes_delete_timecard {
  1076. if ( JC->delete_timecard( \%myconfig, \%$form ) ) {
  1077. $form->redirect( $locale->text('Time Card deleted!') );
  1078. }
  1079. else {
  1080. $form->error( $locale->text('Cannot delete time card!') );
  1081. }
  1082. }
  1083. sub list_timecard {
  1084. $form->{type} = "timecard";
  1085. JC->jcitems( \%myconfig, \%$form );
  1086. $form->{title} = $locale->text('Time Cards');
  1087. @a =
  1088. qw(type direction oldsort path login sessionid project l_subtotal open closed l_time l_allocated);
  1089. $href = "$form->{script}?action=list_timecard";
  1090. for (@a) { $href .= "&$_=$form->{$_}" }
  1091. $href .= "&title=" . $form->escape( $form->{title} );
  1092. $form->sort_order();
  1093. $callback = "$form->{script}?action=list_timecard";
  1094. for (@a) { $callback .= "&$_=$form->{$_}" }
  1095. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1096. @column_index =
  1097. (qw(transdate projectnumber projectdescription id partnumber description)
  1098. );
  1099. push @column_index, (qw(allocated)) if $form->{l_allocated};
  1100. push @column_index, (qw(1 2 3 4 5 6 7));
  1101. @column_index = $form->sort_columns(@column_index);
  1102. if ( $form->{project} eq 'job' ) {
  1103. $joblabel = $locale->text('Job Number');
  1104. $laborlabel = $locale->text('Labor Code');
  1105. $desclabel = $locale->text('Job Name');
  1106. }
  1107. elsif ( $form->{project} eq 'project' ) {
  1108. $joblabel = $locale->text('Project Number');
  1109. $laborlabel = $locale->text('Service Code');
  1110. $desclabel = $locale->text('Project Name');
  1111. }
  1112. else {
  1113. $joblabel = $locale->text('Project/Job Number');
  1114. $laborlabel = $locale->text('Service/Labor Code');
  1115. $desclabel = $locale->text('Project/Job Name');
  1116. }
  1117. if ( $form->{projectnumber} ) {
  1118. $callback .=
  1119. "&projectnumber=" . $form->escape( $form->{projectnumber}, 1 );
  1120. $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
  1121. ($var) = split /--/, $form->{projectnumber};
  1122. $option .= "\n<br>" if ($option);
  1123. $option .= "$joblabel : $var";
  1124. @column_index = grep !/projectnumber/, @column_index;
  1125. }
  1126. if ( $form->{partnumber} ) {
  1127. $callback .= "&partnumber=" . $form->escape( $form->{partnumber}, 1 );
  1128. $href .= "&partnumber=" . $form->escape( $form->{partnumber} );
  1129. ($var) = split /--/, $form->{partnumber};
  1130. $option .= "\n<br>" if ($option);
  1131. $option .= "$laborlabel : $var";
  1132. @column_index = grep !/partnumber/, @column_index;
  1133. }
  1134. if ( $form->{employee} ) {
  1135. $callback .= "&employee=" . $form->escape( $form->{employee}, 1 );
  1136. $href .= "&employee=" . $form->escape( $form->{employee} );
  1137. }
  1138. if ( $form->{startdatefrom} ) {
  1139. $callback .= "&startdatefrom=$form->{startdatefrom}";
  1140. $href .= "&startdatefrom=$form->{startdatefrom}";
  1141. $option .= "\n<br>" if ($option);
  1142. $option .=
  1143. $locale->text('From') . "&nbsp;"
  1144. . $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
  1145. }
  1146. if ( $form->{startdateto} ) {
  1147. $callback .= "&startdateto=$form->{startdateto}";
  1148. $href .= "&startdateto=$form->{startdateto}";
  1149. $option .= "\n<br>" if ($option);
  1150. $option .=
  1151. $locale->text('To') . "&nbsp;"
  1152. . $locale->date( \%myconfig, $form->{startdateto}, 1 );
  1153. }
  1154. if ( $form->{open} ) {
  1155. $callback .= "&open=$form->{open}";
  1156. $href .= "&open=$form->{open}";
  1157. $option .= "\n<br>" if ($option);
  1158. $option .= $locale->text('Open');
  1159. }
  1160. if ( $form->{closed} ) {
  1161. $callback .= "&closed=$form->{closed}";
  1162. $href .= "&closed=$form->{closed}";
  1163. $option .= "\n<br>" if ($option);
  1164. $option .= $locale->text('Closed');
  1165. }
  1166. %weekday = (
  1167. 1 => $locale->text('Sunday'),
  1168. 2 => $locale->text('Monday'),
  1169. 3 => $locale->text('Tuesday'),
  1170. 4 => $locale->text('Wednesday'),
  1171. 5 => $locale->text('Thursday'),
  1172. 6 => $locale->text('Friday'),
  1173. 7 => $locale->text('Saturday'),
  1174. );
  1175. for ( keys %weekday ) {
  1176. $column_header{$_} =
  1177. "<th class=listheading width=25>"
  1178. . substr( $weekday{$_}, 0, 3 ) . "</th>";
  1179. }
  1180. $column_header{id} =
  1181. "<th><a class=listheading href=$href&sort=id>"
  1182. . $locale->text('ID')
  1183. . "</a></th>";
  1184. $column_header{transdate} =
  1185. "<th><a class=listheading href=$href&sort=transdate>"
  1186. . $locale->text('Date')
  1187. . "</a></th>";
  1188. $column_header{description} =
  1189. "<th><a class=listheading href=$href&sort=description>"
  1190. . $locale->text('Description') . "</th>";
  1191. $column_header{projectnumber} =
  1192. "<th><a class=listheading href=$href&sort=projectnumber>$joblabel</a></th>";
  1193. $column_header{partnumber} =
  1194. "<th><a class=listheading href=$href&sort=partnumber>$laborlabel</a></th>";
  1195. $column_header{projectdescription} =
  1196. "<th><a class=listheading href=$href&sort=projectdescription>$desclabel</a></th>";
  1197. $column_header{allocated} = "<th class=listheading></th>";
  1198. $form->header;
  1199. if ( @{ $form->{transactions} } ) {
  1200. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1201. $sameemployeenumber = $form->{transactions}->[0]->{employeenumber};
  1202. $employee = $form->{transactions}->[0]->{employee};
  1203. $sameweek = $form->{transactions}->[0]->{workweek};
  1204. }
  1205. print qq|
  1206. <body>
  1207. <table width=100%>
  1208. <tr>
  1209. <th class=listtop>$form->{title}</th>
  1210. </tr>
  1211. <tr height="5"></tr>
  1212. <tr>
  1213. <td>$option</td>
  1214. </tr>
  1215. <tr>
  1216. <td>
  1217. <table width=100%>
  1218. <tr>
  1219. <th colspan=2 align=left>
  1220. $employee
  1221. </th>
  1222. <th align=left>
  1223. $sameemployeenumber
  1224. </th>
  1225. <tr class=listheading>
  1226. |;
  1227. for (@column_index) { print "\n$column_header{$_}" }
  1228. print qq|
  1229. </tr>
  1230. |;
  1231. # add sort and escape callback, this one we use for the add sub
  1232. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1233. # escape callback for href
  1234. $callback = $form->escape($callback);
  1235. # flip direction
  1236. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1237. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1238. %total = ();
  1239. foreach $ref ( @{ $form->{transactions} } ) {
  1240. if ( $sameemployeenumber ne $ref->{employeenumber} ) {
  1241. $sameemployeenumber = $ref->{employeenumber};
  1242. $sameweek = $ref->{workweek};
  1243. if ( $form->{l_subtotal} ) {
  1244. print qq|
  1245. <tr class=listsubtotal>
  1246. |;
  1247. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1248. $weektotal = 0;
  1249. for ( keys %weekday ) {
  1250. $column_data{$_} = "<th class=listsubtotal align=right>"
  1251. . $form->format_amount( \%myconfig, $subtotal{$_}, "",
  1252. "&nbsp;" )
  1253. . "</th>";
  1254. $weektotal += $subtotal{$_};
  1255. $subtotal{$_} = 0;
  1256. }
  1257. $column_data{ $form->{sort} } =
  1258. "<th class=listsubtotal align=right>"
  1259. . $form->format_amount( \%myconfig, $weektotal, "", "&nbsp;" )
  1260. . "</th>";
  1261. for (@column_index) { print "\n$column_data{$_}" }
  1262. }
  1263. # print total
  1264. print qq|
  1265. <tr class=listtotal>
  1266. |;
  1267. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1268. $total = 0;
  1269. for ( keys %weekday ) {
  1270. $column_data{$_} =
  1271. "<th class=listtotal align=right>"
  1272. . $form->format_amount( \%myconfig, $total{$_}, "", "&nbsp;" )
  1273. . "</th>";
  1274. $total += $total{$_};
  1275. $total{$_} = 0;
  1276. }
  1277. $column_data{ $form->{sort} } =
  1278. "<th class=listtotal align=right>"
  1279. . $form->format_amount( \%myconfig, $total, "", "&nbsp;" )
  1280. . "</th>";
  1281. for (@column_index) { print "\n$column_data{$_}" }
  1282. print qq|
  1283. <tr height=30 valign=bottom>
  1284. <th colspan=2 align=left>
  1285. $ref->{employee}
  1286. </th>
  1287. <th align=left>
  1288. $ref->{employeenumber}
  1289. </th>
  1290. <tr class=listheading>
  1291. |;
  1292. for (@column_index) { print "\n$column_header{$_}" }
  1293. print qq|
  1294. </tr>
  1295. |;
  1296. }
  1297. if ( $form->{l_subtotal} ) {
  1298. if ( $ref->{workweek} != $sameweek ) {
  1299. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1300. $weektotal = 0;
  1301. for ( keys %weekday ) {
  1302. $column_data{$_} = "<th class=listsubtotal align=right>"
  1303. . $form->format_amount( \%myconfig, $subtotal{$_}, "",
  1304. "&nbsp;" )
  1305. . "</th>";
  1306. $weektotal += $subtotal{$_};
  1307. $subtotal{$_} = 0;
  1308. }
  1309. $column_data{ $form->{sort} } =
  1310. "<th class=listsubtotal align=right>"
  1311. . $form->format_amount( \%myconfig, $weektotal, "", "&nbsp;" )
  1312. . "</th>";
  1313. $sameweek = $ref->{workweek};
  1314. print qq|
  1315. <tr class=listsubtotal>
  1316. |;
  1317. for (@column_index) { print "\n$column_data{$_}" }
  1318. print qq|
  1319. </tr>
  1320. |;
  1321. }
  1322. }
  1323. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1324. for ( keys %weekday ) { $column_data{$_} = "<td>&nbsp;</td>" }
  1325. $column_data{allocated} =
  1326. "<td align=right>"
  1327. . $form->format_amount( \%myconfig, $ref->{allocated}, "", "&nbsp;" )
  1328. . "</td>";
  1329. $column_data{ $ref->{weekday} } =
  1330. "<td align=right>"
  1331. . $form->format_amount( \%myconfig, $ref->{qty}, "", "&nbsp;" );
  1332. if ( $form->{l_time} ) {
  1333. $column_data{ $ref->{weekday} } .=
  1334. "<br>$ref->{checkedin}<br>$ref->{checkedout}";
  1335. }
  1336. $column_data{ $ref->{weekday} } .= "</td>";
  1337. $column_data{id} =
  1338. "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
  1339. $subtotal{ $ref->{weekday} } += $ref->{qty};
  1340. $total{ $ref->{weekday} } += $ref->{qty};
  1341. $j++;
  1342. $j %= 2;
  1343. print qq|
  1344. <tr class=listrow$j>
  1345. |;
  1346. for (@column_index) { print "\n$column_data{$_}" }
  1347. print qq|
  1348. </tr>
  1349. |;
  1350. }
  1351. # print last subtotal
  1352. if ( $form->{l_subtotal} ) {
  1353. print qq|
  1354. <tr class=listsubtotal>
  1355. |;
  1356. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1357. $weektotal = 0;
  1358. for ( keys %weekday ) {
  1359. $column_data{$_} =
  1360. "<th class=listsubtotal align=right>"
  1361. . $form->format_amount( \%myconfig, $subtotal{$_}, "", "&nbsp;" )
  1362. . "</th>";
  1363. $weektotal += $subtotal{$_};
  1364. }
  1365. $column_data{ $form->{sort} } =
  1366. "<th class=listsubtotal align=right>"
  1367. . $form->format_amount( \%myconfig, $weektotal, "", "&nbsp;" )
  1368. . "</th>";
  1369. for (@column_index) { print "\n$column_data{$_}" }
  1370. }
  1371. # print last total
  1372. print qq|
  1373. <tr class=listtotal>
  1374. |;
  1375. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1376. $total = 0;
  1377. for ( keys %weekday ) {
  1378. $column_data{$_} =
  1379. "<th class=listtotal align=right>"
  1380. . $form->format_amount( \%myconfig, $total{$_}, "", "&nbsp;" )
  1381. . "</th>";
  1382. $total += $total{$_};
  1383. $total{$_} = 0;
  1384. }
  1385. $column_data{ $form->{sort} } =
  1386. "<th class=listtotal align=right>"
  1387. . $form->format_amount( \%myconfig, $total, "", "&nbsp;" ) . "</th>";
  1388. for (@column_index) { print "\n$column_data{$_}" }
  1389. if ( $form->{project} eq 'job' ) {
  1390. if ( $myconfig{acs} !~ /Production--Production/ ) {
  1391. $i = 1;
  1392. $button{'Production--Add Time Card'}{code} =
  1393. qq|<button class="submit" type="submit" name="action" value="add_time_card">|
  1394. . $locale->text('Add Time Card')
  1395. . qq|</button> |;
  1396. $button{'Production--Add Time Card'}{order} = $i++;
  1397. }
  1398. }
  1399. elsif ( $form->{project} eq 'project' ) {
  1400. if ( $myconfig{acs} !~ /Projects--Projects/ ) {
  1401. $i = 1;
  1402. $button{'Projects--Add Time Card'}{code} =
  1403. qq|<button class="submit" type="submit" name="action" value="add_time_card">|
  1404. . $locale->text('Add Time Card')
  1405. . qq|</button> |;
  1406. $button{'Projects--Add Time Card'}{order} = $i++;
  1407. }
  1408. }
  1409. else {
  1410. if ( $myconfig{acs} !~ /Time Cards--Time Cards/ ) {
  1411. $i = 1;
  1412. $button{'Time Cards--Add Time Card'}{code} =
  1413. qq|<button class="submit" type="submit" name="action" value="add_time_card">|
  1414. . $locale->text('Add Time Card')
  1415. . qq|</button> |;
  1416. $button{'Time Cards--Add Time Card'}{order} = $i++;
  1417. }
  1418. }
  1419. for ( split /;/, $myconfig{acs} ) { delete $button{$_} }
  1420. print qq|
  1421. </tr>
  1422. </table>
  1423. </td>
  1424. </tr>
  1425. <tr>
  1426. <td><hr size=3 noshade></td>
  1427. </tr>
  1428. </table>
  1429. <br>
  1430. <form method=post action=$form->{script}>
  1431. |;
  1432. $form->hide_form(qw(callback path login sessionid project));
  1433. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1434. print $item->{code};
  1435. }
  1436. if ( $form->{lynx} ) {
  1437. require "bin/menu.pl";
  1438. &menubar;
  1439. }
  1440. print qq|
  1441. </form>
  1442. </body>
  1443. </html>
  1444. |;
  1445. }
  1446. sub list_storescard {
  1447. $form->{type} = "storescard";
  1448. JC->jcitems( \%myconfig, \%$form );
  1449. $form->{title} = $locale->text('Stores Cards');
  1450. $href = "$form->{script}?action=list_storescard";
  1451. for (qw(type direction oldsort path login sessionid project)) {
  1452. $href .= "&$_=$form->{$_}";
  1453. }
  1454. $href .= "&title=" . $form->escape( $form->{title} );
  1455. $form->sort_order();
  1456. $callback = "$form->{script}?action=list_storescard";
  1457. for (qw(type direction oldsort path login sessionid project)) {
  1458. $callback .= "&$_=$form->{$_}";
  1459. }
  1460. $callback .= "&title=" . $form->escape( $form->{title}, 1 );
  1461. @column_index =
  1462. $form->sort_columns(
  1463. qw(transdate projectnumber projectdescription id partnumber description qty amount)
  1464. );
  1465. if ( $form->{projectnumber} ) {
  1466. $callback .=
  1467. "&projectnumber=" . $form->escape( $form->{projectnumber}, 1 );
  1468. $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
  1469. ($var) = split /--/, $form->{projectnumber};
  1470. $option .= "\n<br>" if ($option);
  1471. $option .= "$joblabel : $var";
  1472. @column_index = grep !/projectnumber/, @column_index;
  1473. }
  1474. if ( $form->{partnumber} ) {
  1475. $callback .= "&partnumber=" . $form->escape( $form->{partnumber}, 1 );
  1476. $href .= "&partnumber=" . $form->escape( $form->{partnumber} );
  1477. ($var) = split /--/, $form->{partnumber};
  1478. $option .= "\n<br>" if ($option);
  1479. $option .= "$laborlabel : $var";
  1480. @column_index = grep !/partnumber/, @column_index;
  1481. }
  1482. if ( $form->{startdatefrom} ) {
  1483. $callback .= "&startdatefrom=$form->{startdatefrom}";
  1484. $href .= "&startdatefrom=$form->{startdatefrom}";
  1485. $option .= "\n<br>" if ($option);
  1486. $option .=
  1487. $locale->text('From') . "&nbsp;"
  1488. . $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
  1489. }
  1490. if ( $form->{startdateto} ) {
  1491. $callback .= "&startdateto=$form->{startdateto}";
  1492. $href .= "&startdateto=$form->{startdateto}";
  1493. $option .= "\n<br>" if ($option);
  1494. $option .=
  1495. $locale->text('To') . "&nbsp;"
  1496. . $locale->date( \%myconfig, $form->{startdateto}, 1 );
  1497. }
  1498. $column_header{id} =
  1499. "<th><a class=listheading href=$href&sort=id>"
  1500. . $locale->text('ID')
  1501. . "</a></th>";
  1502. $column_header{transdate} =
  1503. "<th><a class=listheading href=$href&sort=transdate>"
  1504. . $locale->text('Date')
  1505. . "</a></th>";
  1506. $column_header{projectnumber} =
  1507. "<th><a class=listheading href=$href&sort=projectnumber>"
  1508. . $locale->text('Job Number')
  1509. . "</a></th>";
  1510. $column_header{projectdescription} =
  1511. "<th><a class=listheading href=$href&sort=projectdescription>"
  1512. . $locale->text('Job Description')
  1513. . "</a></th>";
  1514. $column_header{partnumber} =
  1515. "<th><a class=listheading href=$href&sort=partnumber>"
  1516. . $locale->text('Part Number')
  1517. . "</a></th>";
  1518. $column_header{description} =
  1519. "<th><a class=listheading href=$href&sort=description>"
  1520. . $locale->text('Description')
  1521. . "</a></th>";
  1522. $column_header{qty} =
  1523. "<th class=listheading>" . $locale->text('Qty') . "</th>";
  1524. $column_header{amount} =
  1525. "<th class=listheading>" . $locale->text('Amount') . "</th>";
  1526. $form->header;
  1527. if ( @{ $form->{transactions} } ) {
  1528. $sameitem = $form->{transactions}->[0]->{ $form->{sort} };
  1529. }
  1530. print qq|
  1531. <body>
  1532. <table width=100%>
  1533. <tr>
  1534. <th class=listtop>$form->{title}</th>
  1535. </tr>
  1536. <tr height="5"></tr>
  1537. <tr>
  1538. <td>$option</td>
  1539. </tr>
  1540. <tr>
  1541. <td>
  1542. <table width=100%>
  1543. <tr class=listheading>
  1544. |;
  1545. for (@column_index) { print "\n$column_header{$_}" }
  1546. print qq|
  1547. </tr>
  1548. |;
  1549. # add sort and escape callback, this one we use for the add sub
  1550. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1551. # escape callback for href
  1552. $callback = $form->escape($callback);
  1553. # flip direction
  1554. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  1555. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  1556. $total = 0;
  1557. foreach $ref ( @{ $form->{transactions} } ) {
  1558. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1559. $column_data{qty} =
  1560. qq|<td align=right>|
  1561. . $form->format_amount( \%myconfig, $ref->{qty}, "", "&nbsp;" )
  1562. . "</td>";
  1563. $column_data{amount} =
  1564. qq|<td align=right>|
  1565. . $form->format_amount( \%myconfig, $ref->{qty} * $ref->{sellprice},
  1566. 2 )
  1567. . "</td>";
  1568. $column_data{id} =
  1569. "<td><a href=$form->{script}?action=edit&id=$ref->{id}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{id}</a></td>";
  1570. $total += ( $ref->{qty} * $ref->{sellprice} );
  1571. $j++;
  1572. $j %= 2;
  1573. print qq|
  1574. <tr class=listrow$j>
  1575. |;
  1576. for (@column_index) { print "\n$column_data{$_}" }
  1577. print qq|
  1578. </tr>
  1579. |;
  1580. }
  1581. # print total
  1582. print qq|
  1583. <tr class=listtotal>
  1584. |;
  1585. for (@column_index) { $column_data{$_} = "<td>&nbsp;</td>" }
  1586. $column_data{amount} =
  1587. qq|<th align=right>|
  1588. . $form->format_amount( \%myconfig, $total, 2 ) . "</th";
  1589. for (@column_index) { print "\n$column_data{$_}" }
  1590. if ( $form->{project} eq 'job' ) {
  1591. if ( $myconfig{acs} !~ /Production--Production/ ) {
  1592. $i = 1;
  1593. $button{'Production--Add Stores Card'}{code} =
  1594. qq|<button class="submit" type="submit" name="action" value="add_stores_card">|
  1595. . $locale->text('Add Stores Card')
  1596. . qq|</button> |;
  1597. $button{'Production--Add Stores Card'}{order} = $i++;
  1598. }
  1599. }
  1600. for ( split /;/, $myconfig{acs} ) { delete $button{$_} }
  1601. print qq|
  1602. </tr>
  1603. </table>
  1604. </td>
  1605. </tr>
  1606. <tr>
  1607. <td><hr size=3 noshade></td>
  1608. </tr>
  1609. </table>
  1610. <br>
  1611. <form method=post action=$form->{script}>
  1612. |;
  1613. $form->hide_form(qw(callback path login sessionid project));
  1614. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1615. print $item->{code};
  1616. }
  1617. if ( $form->{lynx} ) {
  1618. require "bin/menu.pl";
  1619. &menubar;
  1620. }
  1621. print qq|
  1622. </form>
  1623. </body>
  1624. </html>
  1625. |;
  1626. }
  1627. sub continue { &{ $form->{nextsub} } }
  1628. sub add_time_card {
  1629. $form->{type} = "timecard";
  1630. &add;
  1631. }
  1632. sub add_stores_card {
  1633. $form->{type} = "storescard";
  1634. &add;
  1635. }
  1636. sub print_options {
  1637. if ( $form->{selectlanguage} ) {
  1638. $form->{"selectlanguage"} =
  1639. $form->unescape( $form->{"selectlanguage"} );
  1640. $form->{"selectlanguage"} =~ s/ selected//;
  1641. $form->{"selectlanguage"} =~
  1642. s/(<option value="\Q$form->{language_code}\E")/$1 selected/;
  1643. $lang = qq|<select name=language_code>$form->{selectlanguage}</select>
  1644. <input type=hidden name=selectlanguage value="|
  1645. . $form->escape( $form->{selectlanguage}, 1 ) . qq|">|;
  1646. }
  1647. $form->{selectformname} = $form->unescape( $form->{selectformname} );
  1648. $form->{selectformname} =~ s/ selected//;
  1649. $form->{selectformname} =~
  1650. s/(<option value="\Q$form->{formname}\E")/$1 selected/;
  1651. $type = qq|<select name=formname>$form->{selectformname}</select>
  1652. <input type=hidden name=selectformname value="|
  1653. . $form->escape( $form->{selectformname}, 1 ) . qq|">|;
  1654. $media = qq|<select name=media>
  1655. <option value="screen">| . $locale->text('Screen');
  1656. $form->{selectformat} = qq|<option value="html">html\n|;
  1657. if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) {
  1658. for ( sort keys %{LedgerSMB::Sysconfig::printer} ) {
  1659. $media .= qq|
  1660. <option value="$_">$_|;
  1661. }
  1662. }
  1663. if ( ${LedgerSMB::Sysconfig::latex} ) {
  1664. $media .= qq|
  1665. <option value="queue">| . $locale->text('Queue');
  1666. $form->{selectformat} .= qq|
  1667. <option value="postscript">| . $locale->text('Postscript') . qq|
  1668. <option value="pdf">| . $locale->text('PDF');
  1669. }
  1670. $format = qq|<select name=format>$form->{selectformat}</select>|;
  1671. $format =~ s/(<option value="\Q$form->{format}\E")/$1 selected/;
  1672. $format .= qq|
  1673. <input type=hidden name=selectformat value="|
  1674. . $form->escape( $form->{selectformat}, 1 ) . qq|">|;
  1675. $media .= qq|</select>|;
  1676. $media =~ s/(<option value="\Q$form->{media}\E")/$1 selected/;
  1677. print qq|
  1678. <table width=100%>
  1679. <tr>
  1680. <td>$type</td>
  1681. <td>$lang</td>
  1682. <td>$format</td>
  1683. <td>$media</td>
  1684. <td align=right width=90%>
  1685. |;
  1686. if ( $form->{printed} =~ /$form->{formname}/ ) {
  1687. print $locale->text('Printed') . qq|<br>|;
  1688. }
  1689. if ( $form->{queued} =~ /$form->{formname}/ ) {
  1690. print $locale->text('Queued');
  1691. }
  1692. print qq|
  1693. </td>
  1694. </tr>
  1695. </table>
  1696. |;
  1697. }
  1698. sub print {
  1699. if ( $form->{media} !~ /screen/ ) {
  1700. $form->error( $locale->text('Select postscript or PDF!') )
  1701. if $form->{format} !~ /(postscript|pdf)/;
  1702. $old_form = new Form;
  1703. for ( keys %$form ) { $old_form->{$_} = $form->{$_} }
  1704. }
  1705. &{"print_$form->{formname}"}($old_form);
  1706. }
  1707. sub print_timecard {
  1708. my ($old_form) = @_;
  1709. $display_form =
  1710. ( $form->{display_form} ) ? $form->{display_form} : "update";
  1711. $form->{description} =~ s/^\s+//g;
  1712. for (qw(partnumber projectnumber)) { $form->{$_} =~ s/--.*// }
  1713. @a = qw(hour min sec);
  1714. foreach $item (qw(in out)) {
  1715. for (@a) { $form->{"$item$_"} = substr( qq|00$form->{"$item$_"}|, -2 ) }
  1716. $form->{"checked$item"} =
  1717. qq|$form->{"${item}hour"}:$form->{"${item}min"}:$form->{"${item}sec"}|;
  1718. }
  1719. @a = ();
  1720. for (qw(company address tel fax businessnumber)) {
  1721. $form->{$_} = $myconfig{$_};
  1722. }
  1723. $form->{address} =~ s/\\n/\n/g;
  1724. push @a, qw(partnumber description projectnumber projectdescription);
  1725. push @a, qw(company address tel fax businessnumber username useremail);
  1726. $form->format_string(@a);
  1727. $form->{total} = $form->format_amount(
  1728. \%myconfig,
  1729. $form->parse_amount( \%myconfig, $form->{qty} ) *
  1730. $form->parse_amount( \%myconfig, $form->{sellprice} ),
  1731. 2
  1732. );
  1733. ( $form->{employee}, $form->{employee_id} ) = split /--/, $form->{employee};
  1734. $form->{templates} = "$myconfig{templates}";
  1735. $form->{IN} = "$form->{formname}.html";
  1736. if ( $form->{format} =~ /(postscript|pdf)/ ) {
  1737. $form->{IN} =~ s/html$/tex/;
  1738. }
  1739. if ( $form->{media} !~ /(screen|queue)/ ) {
  1740. $form->{OUT} = ${LedgerSMB::Sysconfig::printer}{ $form->{media} };
  1741. $form->{printmode} = '|-';
  1742. if ( $form->{printed} !~ /$form->{formname}/ ) {
  1743. $form->{printed} .= " $form->{formname}";
  1744. $form->{printed} =~ s/^ //;
  1745. $form->update_status( \%myconfig );
  1746. }
  1747. %audittrail = (
  1748. tablename => jcitems,
  1749. reference => $form->{id},
  1750. formname => $form->{formname},
  1751. action => 'printed',
  1752. id => $form->{id}
  1753. );
  1754. %status = ();
  1755. for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
  1756. $status{audittrail} .=
  1757. $form->audittrail( "", \%myconfig, \%audittrail );
  1758. }
  1759. if ( $form->{media} eq 'queue' ) {
  1760. %queued = split / /, $form->{queued};
  1761. if ( $filename = $queued{ $form->{formname} } ) {
  1762. $form->{queued} =~ s/$form->{formname} $filename//;
  1763. unlink "${LedgerSMB::Sysconfig::spool}/$filename";
  1764. $filename =~ s/\..*$//g;
  1765. }
  1766. else {
  1767. $filename = time;
  1768. $filename .= $$;
  1769. }
  1770. $filename .= ( $form->{format} eq 'postscript' ) ? '.ps' : '.pdf';
  1771. $form->{OUT} = "${LedgerSMB::Sysconfig::spool}/$filename";
  1772. $form->{printmode} = '>';
  1773. $form->{queued} = "$form->{formname} $filename";
  1774. $form->update_status( \%myconfig );
  1775. %audittrail = (
  1776. tablename => jcitems,
  1777. reference => $form->{id},
  1778. formname => $form->{formname},
  1779. action => 'queued',
  1780. id => $form->{id}
  1781. );
  1782. %status = ();
  1783. for (qw(printed queued audittrail)) { $status{$_} = $form->{$_} }
  1784. $status{audittrail} .=
  1785. $form->audittrail( "", \%myconfig, \%audittrail );
  1786. }
  1787. $form->parse_template( \%myconfig, ${LedgerSMB::Sysconfig::userspath} );
  1788. if ( defined %$old_form ) {
  1789. for ( keys %$old_form ) { $form->{$_} = $old_form->{$_} }
  1790. for (qw(printed queued audittrail)) { $form->{$_} = $status{$_} }
  1791. &{"$display_form"};
  1792. }
  1793. }