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