summaryrefslogtreecommitdiff
path: root/bin/pe.pl
blob: f1c11d35291a238302a19bc136cf92ec51136dce (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # See COPYRIGHT file for copyright information
  8. #======================================================================
  9. #
  10. # This file has NOT undergone whitespace cleanup.
  11. #
  12. #======================================================================
  13. #
  14. # project/job administration
  15. # partsgroup administration
  16. # translation maintainance
  17. #
  18. #======================================================================
  19. use LedgerSMB::PE;
  20. use LedgerSMB::AA;
  21. use LedgerSMB::OE;
  22. 1;
  23. # end of main
  24. sub add {
  25. # construct callback
  26. $form->{callback} =
  27. "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
  28. unless $form->{callback};
  29. &{"prepare_$form->{type}"};
  30. $form->{orphaned} = 1;
  31. &display_form;
  32. }
  33. sub edit {
  34. &{"prepare_$form->{type}"};
  35. &display_form;
  36. }
  37. sub prepare_partsgroup {
  38. PE->get_partsgroup( \%myconfig, \%$form )
  39. if $form->{id};
  40. }
  41. sub prepare_pricegroup {
  42. PE->get_pricegroup( \%myconfig, \%$form )
  43. if $form->{id};
  44. }
  45. sub prepare_job {
  46. # $locale->text('Add Job')
  47. # $locale->text('Edit Job')
  48. $form->{vc} = 'customer';
  49. PE->get_job( \%myconfig, \%$form );
  50. $form->{taxaccounts} = "";
  51. for ( keys %{ $form->{IC_links} } ) {
  52. $form->{"select$_"} = "";
  53. foreach $ref ( @{ $form->{IC_links}{$_} } ) {
  54. if (/IC_tax/) {
  55. if (/taxpart/) {
  56. $form->{taxaccounts} .= "$ref->{accno} ";
  57. $form->{"IC_tax_$ref->{accno}_description"} =
  58. "$ref->{accno}--$ref->{description}";
  59. if ( $form->{id} ) {
  60. if ( $form->{amount}{ $ref->{accno} } ) {
  61. $form->{"IC_tax_$ref->{accno}"} = "checked";
  62. }
  63. }
  64. else {
  65. $form->{"IC_tax_$ref->{accno}"} = "checked";
  66. }
  67. }
  68. }
  69. else {
  70. $form->{"select$_"} .=
  71. "<option>$ref->{accno}--$ref->{description}\n";
  72. }
  73. }
  74. }
  75. chop $form->{taxaccounts};
  76. $form->{selectIC_income} = $form->{selectIC_sale};
  77. $form->{IC_income} = $form->{IC_sale};
  78. $form->{IC_income} = qq|$form->{income_accno}--$form->{income_description}|;
  79. delete $form->{IC_links};
  80. $form->{"old$form->{vc}"} =
  81. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  82. if ( @{ $form->{"all_$form->{vc}"} } ) {
  83. $form->{"$form->{vc}"} =
  84. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  85. $form->{"select$form->{vc}"} = qq|<option>\n|;
  86. for ( @{ $form->{"all_$form->{vc}"} } ) {
  87. $form->{"select$form->{vc}"} .=
  88. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  89. }
  90. }
  91. $form->get_partsgroup( \%myconfig, { all => 1 } );
  92. $form->{partsgroup} =
  93. $form->quote( $form->{partsgroup} ) . "--$form->{partsgroup_id}";
  94. if ( @{ $form->{all_partsgroup} } ) {
  95. $form->{selectpartsgroup} = qq|<option>\n|;
  96. for ( @{ $form->{all_partsgroup} } ) {
  97. $form->{selectpartsgroup} .=
  98. qq|<option value="|
  99. . $form->quote( $_->{partsgroup} )
  100. . qq|--$_->{id}">$_->{partsgroup}\n|;
  101. }
  102. }
  103. $form->{locked} =
  104. ( $form->{revtrans} )
  105. ? '1'
  106. : ( $form->datetonum( \%myconfig, $form->{transdate} ) <=
  107. $form->datetonum( \%myconfig, $form->{closedto} ) );
  108. $form->{readonly} = 1 if $myconfig{acs} =~ /Job Costing--Add Job/;
  109. }
  110. sub job_header {
  111. for (qw(partnumber partdescription description notes unit)) {
  112. $form->{$_} = $form->quote( $form->{$_} );
  113. }
  114. for (qw(production weight)) {
  115. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_} );
  116. }
  117. for (qw(listprice sellprice)) {
  118. $form->{$_} = $form->format_amount( \%myconfig, $form->{$_}, 2 );
  119. }
  120. if ( ( $rows = $form->numtextrows( $form->{partdescription}, 60 ) ) > 1 ) {
  121. $partdescription =
  122. qq|<textarea name="partdescription" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{partdescription}</textarea>|;
  123. }
  124. else {
  125. $partdescription =
  126. qq|<input name=partdescription size=60 value="$form->{partdescription}">|;
  127. }
  128. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  129. $description =
  130. qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
  131. }
  132. else {
  133. $description =
  134. qq|<input name=description size=60 value="$form->{description}">|;
  135. }
  136. if ( ( $rows = $form->numtextrows( $form->{notes}, 40 ) ) < 2 ) {
  137. $rows = 2;
  138. }
  139. $notes =
  140. qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
  141. $form->{selectIC_income} = $form->unescape( $form->{selectIC_income} );
  142. $form->{"select$form->{vc}"} =
  143. $form->unescape( $form->{"select$form->{vc}"} );
  144. $form->{"select$form->{vc}"} =~ s/ selected//;
  145. $form->{"select$form->{vc}"} =~
  146. s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
  147. $label = ucfirst $form->{vc};
  148. if ( $form->{"select$form->{vc}"} ) {
  149. $name = qq|
  150. <tr>
  151. <th align=right nowrap>| . $locale->text($label) . qq|</th>
  152. <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
  153. <input type=hidden name="select$form->{vc}" value="|
  154. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
  155. </tr>
  156. |;
  157. }
  158. else {
  159. $name = qq|
  160. <tr>
  161. <th align=right nowrap>| . $locale->text($label) . qq|</th>
  162. <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
  163. <input type=hidden name="select$form->{vc}" value="|
  164. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
  165. </tr>
  166. |;
  167. }
  168. if ( $form->{orphaned} ) {
  169. for (qw(income)) {
  170. $form->{"selectIC_$_"} =~ s/ selected//;
  171. $form->{"selectIC_$_"} =~
  172. s/option>\Q$form->{"IC_$_"}\E/option selected>$form->{"IC_$_"}/;
  173. }
  174. $production = qq|
  175. <tr>
  176. <th align=right nowrap>| . $locale->text('Production') . qq|</th>
  177. <td><input name=production size=10 value="$form->{production}"></td>
  178. <th align=right nowrap>| . $locale->text('Completed') . qq|</th>
  179. <td>$form->{completed}</td>
  180. </tr>
  181. |;
  182. }
  183. else {
  184. $form->{selectIC_income} = qq|<option selected>$form->{IC_income}|;
  185. $production = qq|
  186. <tr>
  187. <th align=right nowrap>| . $locale->text('Production') . qq|</th>
  188. <td><input type=hidden name=production value="$form->{production}">$form->{production}</td>
  189. <th align=right nowrap>| . $locale->text('Completed') . qq|</th>
  190. <td>$form->{completed}</td>
  191. </tr>
  192. |;
  193. }
  194. for ( split / /, $form->{taxaccounts} ) {
  195. $form->{"IC_tax_$_"} = ( $form->{"IC_tax_$_"} ) ? "checked" : "";
  196. }
  197. if ( $form->{selectpartsgroup} ) {
  198. $form->{selectpartsgroup} =
  199. $form->unescape( $form->{selectpartsgroup} );
  200. $partsgroup =
  201. qq|<input type=hidden name=selectpartsgroup value="|
  202. . $form->escape( $form->{selectpartsgroup}, 1 ) . qq|">|;
  203. $form->{partsgroup} = $form->quote( $form->{partsgroup} );
  204. $form->{selectpartsgroup} =~
  205. s/(<option value="\Q$form->{partsgroup}\E")/$1 selected/;
  206. $partsgroup .=
  207. qq|\n<select name=partsgroup>$form->{selectpartsgroup}</select>|;
  208. $group = $locale->text('Group');
  209. }
  210. $linkaccounts = qq|
  211. <tr>
  212. <th align=right nowrap>| . $locale->text('Income') . qq|</th>
  213. <td><select name=IC_income>$form->{selectIC_income}</select></td>
  214. </tr>
  215. |;
  216. for ( split / /, $form->{taxaccounts} ) {
  217. $tax .= qq|
  218. <input class=checkbox type=checkbox name="IC_tax_$_" value=1 $form->{"IC_tax_$_"}>&nbsp;<b>$form->{"IC_tax_${_}_description"}</b>
  219. <br><input type=hidden name=IC_tax_${_}_description value="$form->{"IC_tax_${_}_description"}">
  220. |;
  221. }
  222. if ($tax) {
  223. $linkaccounts .= qq|
  224. <tr>
  225. <th align=right>| . $locale->text('Tax') . qq|</th>
  226. <td>$tax</td>
  227. </tr>
  228. |;
  229. }
  230. $partnumber = qq|
  231. <tr>
  232. <td>
  233. <table>
  234. <tr valign=top>
  235. <th align=left>| . $locale->text('Number') . qq|</th>
  236. <th align=left>| . $locale->text('Description') . qq|</th>
  237. <th align=left>$group</th>
  238. </tr>
  239. <tr valign=top>
  240. <td><input name=partnumber value="$form->{partnumber}" size=20></td>
  241. <td>$partdescription</td>
  242. <td>$partsgroup</td>
  243. </tr>
  244. </table>
  245. </td>
  246. </tr>
  247. |;
  248. $form->{title} =
  249. ( $form->{id} ) ? $locale->text('Edit Job') : $locale->text('Add Job');
  250. $form->header;
  251. print qq|
  252. <body>
  253. <form method=post action=$form->{script}>
  254. |;
  255. for (qw(partnumber startdate enddate)) { $form->{"old$_"} = $form->{$_} }
  256. print qq|<input type=hidden name="selectIC_income" value="|
  257. . $form->escape( $form->{"selectIC_income"}, 1 )
  258. . qq|">\n|;
  259. $form->hide_form(
  260. "id", "type",
  261. "old$form->{vc}", "$form->{vc}_id",
  262. "orphaned", "taxaccounts",
  263. "vc", "project"
  264. );
  265. print qq|
  266. <table width=100%>
  267. <tr>
  268. <th class=listtop>$form->{title}</th>
  269. </tr>
  270. <tr height="5"></tr>
  271. <tr>
  272. <td>
  273. <table>
  274. <tr>
  275. <th align=right>| . $locale->text('Number') . qq|</th>
  276. <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
  277. <th align=right>| . $locale->text('Description') . qq|</th>
  278. <td>$description</td>
  279. </tr>
  280. $name
  281. <tr>
  282. <th align=right>| . $locale->text('Startdate') . qq|</th>
  283. <td><input class="date" name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
  284. <th align=right>| . $locale->text('Enddate') . qq|</th>
  285. <td><input class="date" name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
  286. </tr>
  287. $production
  288. </table>
  289. </td>
  290. </tr>
  291. <tr class="listheading">
  292. <th class="listheading" align="center">|
  293. . $locale->text('Assembly')
  294. . qq|</th>
  295. </tr>
  296. <tr>
  297. <td>
  298. <table width=100%>
  299. $partnumber
  300. <tr>
  301. <td colspan=3>
  302. <table width=100%>
  303. <tr>
  304. <td width=70%>
  305. <table width=100%>
  306. <tr class="listheading">
  307. <th class="listheading" align="center" colspan=2>|
  308. . $locale->text('Link Accounts')
  309. . qq|</th>
  310. </tr>
  311. $linkaccounts
  312. <tr>
  313. <th align="left">| . $locale->text('Notes') . qq|</th>
  314. </tr>
  315. <tr>
  316. <td colspan=2>
  317. $notes
  318. </td>
  319. </tr>
  320. </table>
  321. </td>
  322. <td align=right>
  323. <table>
  324. <tr>
  325. <th align="right" nowrap="true">| . $locale->text('Updated') . qq|</th>
  326. <td><input name=priceupdate size=11 title="$myconfig{dateformat}" value=$form->{priceupdate}></td>
  327. </tr>
  328. <tr>
  329. <th align="right" nowrap="true">|
  330. . $locale->text('List Price')
  331. . qq|</th>
  332. <td><input name=listprice size=11 value=$form->{listprice}></td>
  333. </tr>
  334. <tr>
  335. <th align="right" nowrap="true">|
  336. . $locale->text('Sell Price')
  337. . qq|</th>
  338. <td><input name=sellprice size=11 value=$form->{sellprice}></td>
  339. </tr>
  340. <tr>
  341. <th align="right" nowrap="true">| . $locale->text('Weight') . qq|</th>
  342. <td>
  343. <table>
  344. <tr>
  345. <td>
  346. <input name=weight size=10 value=$form->{weight}>
  347. </td>
  348. <th>
  349. &nbsp;
  350. $form->{weightunit}
  351. <input type=hidden name=weightunit value=$form->{weightunit}>
  352. </th>
  353. </tr>
  354. </table>
  355. </td>
  356. <tr>
  357. <th align="right" nowrap="true">| . $locale->text('Bin') . qq|</th>
  358. <td><input name=bin size=10 value="$form->{bin}"></td>
  359. </tr>
  360. <tr>
  361. <th align="right" nowrap="true">| . $locale->text('Unit') . qq|</th>
  362. <td><input name=unit size=5 value="$form->{unit}"></td>
  363. </tr>
  364. </table>
  365. </td>
  366. </tr>
  367. </table>
  368. </td>
  369. </tr>
  370. </table>
  371. </td>
  372. </tr>
  373. <tr>
  374. <td><hr size=3 noshade></td>
  375. </tr>
  376. </table>
  377. |;
  378. }
  379. sub job_footer {
  380. $form->hide_form(qw(callback path login sessionid));
  381. # type=submit $locale->text('Update')
  382. # type=submit $locale->text('Save')
  383. # type=submit $locale->text('Delete')
  384. %button =
  385. ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  386. );
  387. if ( $myconfig{acs} !~ /Job Costing--Add Job/ ) {
  388. $button{'save'} =
  389. { ndx => 3, key => 'S', value => $locale->text('Save') };
  390. if ( $form->{id} && $form->{orphaned} ) {
  391. $button{'delete'} =
  392. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  393. }
  394. }
  395. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  396. $form->print_button( \%button, $_ );
  397. }
  398. if ( $form->{lynx} ) {
  399. require "bin/menu.pl";
  400. &menubar;
  401. }
  402. print qq|
  403. </form>
  404. </body>
  405. </html>
  406. |;
  407. }
  408. sub list_stock {
  409. PE->list_stock( \%myconfig, \%$form );
  410. $form->{title} = $locale->text('Stock Finished Goods');
  411. $form->{action} = "list_stock";
  412. $href = "$form->{script}?";
  413. for (qw(action direction oldsort type path login sessionid status)) {
  414. $href .= "$_=$form->{$_}&";
  415. }
  416. $form->sort_order();
  417. $callback = "$form->{script}?";
  418. for (qw(action direction oldsort type path login sessionid status)) {
  419. $callback .= "$_=$form->{$_}&";
  420. }
  421. @column_index =
  422. $form->sort_columns(
  423. qw(projectnumber description startdate partnumber production completed stock)
  424. );
  425. if ( $form->{projectnumber} ) {
  426. $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
  427. $callback .= "&projectnumber=$form->{projectnumber}";
  428. ($var) = split /--/, $form->{projectnumber};
  429. $option .= "\n<br>" . $locale->text('Job Number') . " : $var";
  430. }
  431. if ( $form->{stockingdate} ) {
  432. $href .= "&stockingdate=$form->{stockingdate}";
  433. $option .= "\n<br>"
  434. . $locale->text('As of') . " : "
  435. . $locale->date( \%myconfig, $form->{stockingdate}, 1 );
  436. }
  437. $column_header{projectnumber} =
  438. qq|<th width=30%><a class=listheading href=$href&sort=projectnumber>|
  439. . $locale->text('Number')
  440. . qq|</a></th>|;
  441. $column_header{description} =
  442. qq|<th width=50%><a class=listheading href=$href&sort=description>|
  443. . $locale->text('Description')
  444. . qq|</a></th>|;
  445. $column_header{startdate} =
  446. qq|<th width=10%><a class=listheading href=$href&sort=startdate>|
  447. . $locale->text('Startdate')
  448. . qq|</a></th>|;
  449. $column_header{partnumber} =
  450. "<th><a class=listheading href=$href&sort=partnumber>"
  451. . $locale->text('Assembly')
  452. . "</a></th>";
  453. $column_header{production} =
  454. "<th class=listheading>" . $locale->text('Production') . "</a></th>";
  455. $column_header{completed} =
  456. "<th class=listheading>" . $locale->text('Completed') . "</a></th>";
  457. $column_header{stock} =
  458. "<th class=listheading>" . $locale->text('Add') . "</a></th>";
  459. $form->header;
  460. if ( @{ $form->{all_project} } ) {
  461. $sameitem = $form->{all_project}->[0]->{ $form->{sort} };
  462. }
  463. print qq|
  464. <body>
  465. <form method=post action=$form->{script}>
  466. <table width=100%>
  467. <tr>
  468. <th class=listtop>$form->{title}</th>
  469. </tr>
  470. <tr height="5"></tr>
  471. <tr>
  472. <td>$option</td>
  473. </tr>
  474. <tr>
  475. <td>
  476. <table width=100%>
  477. <tr class=listheading>
  478. |;
  479. for (@column_index) { print "$column_header{$_}\n" }
  480. print qq|
  481. </tr>
  482. |;
  483. # escape callback
  484. $form->{callback} = $callback .= "&sort=$form->{sort}";
  485. # escape callback for href
  486. $callback = $form->escape($callback);
  487. # flip direction
  488. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  489. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  490. $i = 0;
  491. foreach $ref ( @{ $form->{all_project} } ) {
  492. $i++;
  493. for (qw(projectnumber description startdate enddate partnumber)) {
  494. $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
  495. }
  496. for (qw(production completed)) {
  497. $column_data{$_} =
  498. qq|<td align=right>|
  499. . $form->format_amount( \%myconfig, $ref->{$_} )
  500. . qq|</td>|;
  501. }
  502. $column_data{stock} = qq|<td><input name="stock_$i" size=6></td>|;
  503. $j++;
  504. $j %= 2;
  505. print qq|
  506. <tr valign=top class=listrow$j>
  507. <input type=hidden name="id_$i" value=$ref->{id}>
  508. |;
  509. for (@column_index) { print "$column_data{$_}\n" }
  510. print "
  511. </tr>
  512. ";
  513. }
  514. print qq|
  515. </table>
  516. </td>
  517. </tr>
  518. <tr>
  519. <td><hr size=3 noshade></td>
  520. </tr>
  521. </table>
  522. |;
  523. $form->hide_form(qw(callback type path login sessionid status));
  524. print qq|
  525. <input type="hidden" name="nextsub" value="stock">
  526. <br>
  527. <button type="submit" class="submit" name="action" value="continue">|
  528. . $locale->text('Continue')
  529. . qq|</button>
  530. </form>
  531. </body>
  532. </html>
  533. |;
  534. }
  535. sub stock {
  536. if ( PE->stock_assembly( \%myconfig, \%$form ) ) {
  537. $form->redirect( $locale->text('Assembly stocked!') );
  538. }
  539. else {
  540. $form->error( $locale->text('Cannot stock Assembly!') );
  541. }
  542. }
  543. sub prepare_project {
  544. $form->{vc} = 'customer';
  545. PE->get_project( \%myconfig, \%$form );
  546. $form->{title} =
  547. ( $form->{id} )
  548. ? $locale->text('Edit Project')
  549. : $locale->text('Add Project');
  550. $form->{"old$form->{vc}"} =
  551. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  552. if ( @{ $form->{"all_$form->{vc}"} } ) {
  553. $form->{"$form->{vc}"} =
  554. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  555. $form->{"select$form->{vc}"} = qq|<option>\n|;
  556. for ( @{ $form->{"all_$form->{vc}"} } ) {
  557. $form->{"select$form->{vc}"} .=
  558. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  559. }
  560. }
  561. }
  562. sub search {
  563. # accounting years
  564. $form->all_years( \%myconfig );
  565. if ( @{ $form->{all_years} } ) {
  566. $form->{selectaccountingyear} = "<option>\n";
  567. for ( @{ $form->{all_years} } ) {
  568. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  569. }
  570. $form->{selectaccountingmonth} = "<option>\n";
  571. for ( sort keys %{ $form->{all_month} } ) {
  572. $form->{selectaccountingmonth} .=
  573. qq|<option value=$_>|
  574. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  575. }
  576. $fromto = qq|
  577. <tr>
  578. <th align=right>| . $locale->text('Startdate') . qq|</th>
  579. <td>|
  580. . $locale->text('From')
  581. . qq| <input class="date" name=startdatefrom size=11 title="($myconfig{'dateformat'})">|
  582. . $locale->text('To') . qq|
  583. <input class="date" name=startdateto size=11 title="($myconfig{'dateformat'})"></td>
  584. </tr>
  585. |;
  586. $selectperiod = qq|
  587. <tr>
  588. <th align=right>| . $locale->text('Period') . qq|</th>
  589. <td colspan=3>
  590. <select name=month>$form->{selectaccountingmonth}</select>
  591. <select name=year>$form->{selectaccountingyear}</select>
  592. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  593. . $locale->text('Current') . qq|
  594. <input name=interval class=radio type=radio value=1>&nbsp;|
  595. . $locale->text('Month') . qq|
  596. <input name=interval class=radio type=radio value=3>&nbsp;|
  597. . $locale->text('Quarter') . qq|
  598. <input name=interval class=radio type=radio value=12>&nbsp;|
  599. . $locale->text('Year') . qq|
  600. </td>
  601. </tr>
  602. |;
  603. }
  604. $orphaned = qq|
  605. <input name=status class=radio type=radio value=orphaned>&nbsp;|
  606. . $locale->text('Orphaned');
  607. if ( $form->{type} eq 'project' ) {
  608. $report = "project_report";
  609. $sort = "projectnumber";
  610. $form->{title} = $locale->text('Projects');
  611. $number = qq|
  612. <tr>
  613. <th align=right width=1%>| . $locale->text('Number') . qq|</th>
  614. <td><input name=projectnumber size=20></td>
  615. </tr>
  616. <tr>
  617. <th align=right>| . $locale->text('Description') . qq|</th>
  618. <td><input name=description size=60></td>
  619. </tr>
  620. |;
  621. }
  622. if ( $form->{type} eq 'stock' ) {
  623. $report = "list_stock";
  624. $form->{title} = $locale->text('Stock Finished Goods');
  625. PE->list_stock( \%myconfig, \%$form );
  626. $selectperiod = "";
  627. $orphaned = "";
  628. $fromto = qq|
  629. <tr>
  630. <th align=right nowrap>| . $locale->text('As of') . qq|</th>
  631. <td><input class="date" name=stockingdate size=11 title="$myconfig{dateformat}"></td>
  632. </tr>
  633. |;
  634. $number = qq|
  635. <tr>
  636. <th align=right width=1%>| . $locale->text('Job Number') . qq|</th>
  637. <td><input name=projectnumber size=20></td>
  638. </tr>
  639. <tr>
  640. <th align=right>| . $locale->text('Description') . qq|</th>
  641. <td><input name=description size=60></td>
  642. </tr>
  643. |;
  644. }
  645. if ( $form->{type} eq 'job' ) {
  646. $report = "job_report";
  647. $sort = "projectnumber";
  648. $form->{title} = $locale->text('Jobs');
  649. $number = qq|
  650. <tr>
  651. <th align=right width=1%>| . $locale->text('Number') . qq|</th>
  652. <td><input name=projectnumber size=20></td>
  653. </tr>
  654. <tr>
  655. <th align=right>| . $locale->text('Description') . qq|</th>
  656. <td><input name=description size=60></td>
  657. </tr>
  658. |;
  659. }
  660. if ( $form->{type} eq 'partsgroup' ) {
  661. $report = "partsgroup_report";
  662. $sort = 'partsgroup';
  663. $form->{title} = $locale->text('Groups');
  664. $fromto = "";
  665. $selectperiod = "";
  666. $number = qq|
  667. <tr>
  668. <th align=right width=1%>| . $locale->text('Group') . qq|</th>
  669. <td><input name=partsgroup size=20></td>
  670. </tr>
  671. |;
  672. }
  673. if ( $form->{type} eq 'pricegroup' ) {
  674. $report = "pricegroup_report";
  675. $sort = 'pricegroup';
  676. $form->{title} = $locale->text('Pricegroups');
  677. $fromto = "";
  678. $selectperiod = "";
  679. $number = qq|
  680. <tr>
  681. <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
  682. <td><input name=pricegroup size=20></td>
  683. </tr>
  684. |;
  685. }
  686. $form->header;
  687. print qq|
  688. <body>
  689. <form method=post action=$form->{script}>
  690. <input type=hidden name=sort value=$sort>
  691. <input type=hidden name=type value=$form->{type}>
  692. <table width=100%>
  693. <tr>
  694. <th class=listtop>$form->{title}</th>
  695. </tr>
  696. <tr height="5"></tr>
  697. <tr>
  698. <td>
  699. <table width=100%>
  700. $number
  701. $fromto
  702. $selectperiod
  703. <tr>
  704. <td></td>
  705. <td><input name=status class=radio type=radio value=all checked>&nbsp;|
  706. . $locale->text('All') . qq|
  707. <input name=status class=radio type=radio value=active>&nbsp;|
  708. . $locale->text('Active') . qq|
  709. <input name=status class=radio type=radio value=inactive>&nbsp;|
  710. . $locale->text('Inactive') . qq|
  711. $orphaned</td>
  712. </tr>
  713. </table>
  714. </td>
  715. </tr>
  716. <tr>
  717. <td><hr size=3 noshade></td>
  718. </tr>
  719. </table>
  720. <input type=hidden name=nextsub value=$report>
  721. |;
  722. $form->hide_form(qw(path login sessionid title));
  723. print qq|
  724. <button class="submit" type="submit" name="action" value="continue">|
  725. . $locale->text('Continue')
  726. . qq|</button>
  727. </form>
  728. |;
  729. if ( $form->{lynx} ) {
  730. require "bin/menu.pl";
  731. &menubar;
  732. }
  733. print qq|
  734. </body>
  735. </html>
  736. |;
  737. }
  738. sub job_report {
  739. for (qw(projectnumber description)) {
  740. $form->{$_} = $form->unescape( $form->{$_} );
  741. }
  742. PE->jobs( \%myconfig, \%$form );
  743. $form->{action} = "job_report";
  744. &list_projects;
  745. }
  746. sub project_report {
  747. for (qw(projectnumber description)) {
  748. $form->{$_} = $form->unescape( $form->{$_} );
  749. }
  750. PE->projects( \%myconfig, \%$form );
  751. $form->{action} = "project_report";
  752. &list_projects;
  753. }
  754. sub list_projects {
  755. $href = "$form->{script}?";
  756. for (
  757. qw(action direction oldsort type path login sessionid status startdatefrom startdateto)
  758. )
  759. {
  760. $href .= "$_=$form->{$_}&";
  761. }
  762. $form->sort_order();
  763. $callback = "$form->{script}?";
  764. for (
  765. qw(action direction oldsort type path login sessionid status startdatefrom startdateto)
  766. )
  767. {
  768. $callback .= "$_=$form->{$_}&";
  769. }
  770. @column_index =
  771. $form->sort_columns(qw(projectnumber description name startdate enddate));
  772. if ( $form->{status} eq 'all' ) {
  773. $option = $locale->text('All');
  774. }
  775. if ( $form->{status} eq 'orphaned' ) {
  776. $option .= $locale->text('Orphaned');
  777. }
  778. if ( $form->{status} eq 'active' ) {
  779. $option = $locale->text('Active');
  780. @column_index =
  781. $form->sort_columns(qw(projectnumber description name startdate));
  782. }
  783. if ( $form->{status} eq 'inactive' ) {
  784. $option = $locale->text('Inactive');
  785. }
  786. if ( $form->{type} eq 'project' ) {
  787. $label = $locale->text('Project');
  788. $form->{title} = $locale->text('Projects');
  789. }
  790. else {
  791. $label = $locale->text('Job');
  792. push @column_index, qw(partnumber production completed);
  793. $form->{title} = $locale->text('Jobs');
  794. }
  795. if ( $form->{projectnumber} ) {
  796. $href .= "&projectnumber=" . $form->escape( $form->{projectnumber} );
  797. $callback .= "&projectnumber=$form->{projectnumber}";
  798. $option .= "\n<br>$label : $form->{projectnumber}";
  799. }
  800. if ( $form->{description} ) {
  801. $href .= "&description=" . $form->escape( $form->{description} );
  802. $callback .= "&description=$form->{description}";
  803. $option .=
  804. "\n<br>" . $locale->text('Description') . " : $form->{description}";
  805. }
  806. if ( $form->{startdatefrom} ) {
  807. $href .= "&startdatefrom=$form->{startdatefrom}";
  808. $option .= "\n<br>"
  809. . $locale->text('From')
  810. . "&nbsp;"
  811. . $locale->date( \%myconfig, $form->{startdatefrom}, 1 );
  812. }
  813. if ( $form->{startdateto} ) {
  814. $href .= "&startdateto=$form->{startdateto}";
  815. if ( $form->{startdatefrom} ) {
  816. $option .= " ";
  817. }
  818. else {
  819. $option .= "\n<br>" if ($option);
  820. }
  821. $option .=
  822. $locale->text('To') . "&nbsp;"
  823. . $locale->date( \%myconfig, $form->{startdateto}, 1 );
  824. }
  825. $column_header{projectnumber} =
  826. qq|<th><a class=listheading href=$href&sort=projectnumber>|
  827. . $locale->text('Number')
  828. . qq|</a></th>|;
  829. $column_header{description} =
  830. qq|<th><a class=listheading href=$href&sort=description>|
  831. . $locale->text('Description')
  832. . qq|</a></th>|;
  833. $column_header{startdate} =
  834. qq|<th width=10><a class=listheading href=$href&sort=startdate>|
  835. . $locale->text('Startdate')
  836. . qq|</a></th>|;
  837. $column_header{enddate} =
  838. qq|<th width=10><a class=listheading href=$href&sort=enddate>|
  839. . $locale->text('Enddate')
  840. . qq|</a></th>|;
  841. $column_header{partnumber} =
  842. "<th><a class=listheading href=$href&sort=partnumber>"
  843. . $locale->text('Assembly')
  844. . "</a></th>";
  845. $column_header{production} =
  846. "<th width=10 class=listheading>" . $locale->text('Production') . "</th>";
  847. $column_header{completed} =
  848. "<th width=10 class=listheading>" . $locale->text('Completed') . "</th>";
  849. $column_header{name} =
  850. "<th class=listheading>" . $locale->text('Customer') . "</th>";
  851. $form->header;
  852. if ( @{ $form->{all_project} } ) {
  853. $sameitem = $form->{all_project}->[0]->{ $form->{sort} };
  854. }
  855. print qq|
  856. <body>
  857. <table width=100%>
  858. <tr>
  859. <th class=listtop>$form->{title}</th>
  860. </tr>
  861. <tr height="5"></tr>
  862. <tr>
  863. <td>$option</td>
  864. </tr>
  865. <tr>
  866. <td>
  867. <table width=100%>
  868. <tr class=listheading>
  869. |;
  870. for (@column_index) { print "$column_header{$_}\n" }
  871. print qq|
  872. </tr>
  873. |;
  874. # escape callback
  875. $form->{callback} = $callback .= "&sort=$form->{sort}";
  876. # escape callback for href
  877. $callback = $form->escape($callback);
  878. # flip direction
  879. $direction = ( $form->{direction} eq 'ASC' ) ? "ASC" : "DESC";
  880. $href =~ s/&direction=(\w+)&/&direction=$direction&/;
  881. foreach $ref ( @{ $form->{all_project} } ) {
  882. for (qw(description startdate enddate name)) {
  883. $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
  884. }
  885. for (qw(production completed)) {
  886. $column_data{$_} =
  887. qq|<td align=right>|
  888. . $form->format_amount( \%myconfig, $ref->{$_} );
  889. }
  890. $column_data{projectnumber} =
  891. qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&project=$form->{project}&callback=$callback>$ref->{projectnumber}</td>|;
  892. $column_data{partnumber} =
  893. qq|<td><a href=ic.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partnumber}</td>|;
  894. $j++;
  895. $j %= 2;
  896. print qq|
  897. <tr valign=top class=listrow$j>
  898. |;
  899. for (@column_index) { print "$column_data{$_}\n" }
  900. print "
  901. </tr>
  902. ";
  903. }
  904. $i = 1;
  905. if ( $form->{type} eq 'project' ) {
  906. if ( $myconfig{acs} !~ /Projects--Projects/ ) {
  907. $button{'Projects--Add Project'}{code} =
  908. qq|<button class="submit" type="submit" name="action" value="add_project">|
  909. . $locale->text('Add Project')
  910. . qq|</button> |;
  911. $button{'Projects--Add Project'}{order} = $i++;
  912. for ( split /;/, $myconfig{acs} ) {
  913. delete $button{$_};
  914. }
  915. }
  916. }
  917. else {
  918. if ( $myconfig{acs} !~ /Job Costing--Job Costing/ ) {
  919. $button{'Job Costing--Add Job'}{code} =
  920. qq|<button class="submit" type="submit" name="action" value="add_job">|
  921. . $locale->text('Add Job')
  922. . qq|</button> |;
  923. $button{'Job Costing--Add Job'}{order} = $i++;
  924. for ( split /;/, $myconfig{acs} ) {
  925. delete $button{$_};
  926. }
  927. }
  928. }
  929. print qq|
  930. </table>
  931. </td>
  932. </tr>
  933. <tr>
  934. <td><hr size=3 noshade></td>
  935. </tr>
  936. </table>
  937. <br>
  938. <form method=post action=$form->{script}>
  939. |;
  940. $form->hide_form(qw(callback type path login sessionid));
  941. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  942. print $item->{code};
  943. }
  944. if ( $form->{lynx} ) {
  945. require "bin/menu.pl";
  946. &menubar;
  947. }
  948. print qq|
  949. </form>
  950. </body>
  951. </html>
  952. |;
  953. }
  954. sub project_header {
  955. $form->{description} = $form->quote( $form->{description} );
  956. if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) {
  957. $description =
  958. qq|<textarea name="description" rows=$rows cols=60 style="width: 100%" wrap=soft>$form->{description}</textarea>|;
  959. }
  960. else {
  961. $description =
  962. qq|<input name=description size=60 value="$form->{description}">|;
  963. }
  964. $form->{"select$form->{vc}"} =
  965. $form->unescape( $form->{"select$form->{vc}"} );
  966. $form->{"select$form->{vc}"} =~ s/ selected//;
  967. $form->{"select$form->{vc}"} =~
  968. s/(<option value="\Q$form->{"$form->{vc}"}\E")/$1 selected/;
  969. $label = ucfirst $form->{vc};
  970. if ( $form->{"select$form->{vc}"} ) {
  971. $name = qq|
  972. <tr>
  973. <th align=right nowrap>| . $locale->text($label) . qq|</th>
  974. <td colspan=3><select name="$form->{vc}">$form->{"select$form->{vc}"}</select></td>
  975. <input type=hidden name="select$form->{vc}" value="|
  976. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
  977. </tr>
  978. |;
  979. }
  980. else {
  981. $name = qq|
  982. <tr>
  983. <th align=right nowrap>| . $locale->text($label) . qq|</th>
  984. <td colspan=3><input name="$form->{vc}" value="$form->{"$form->{vc}"}" size=35></td>
  985. <input type=hidden name="select$form->{vc}" value="|
  986. . $form->escape( $form->{"select$form->{vc}"}, 1 ) . qq|">
  987. </tr>
  988. |;
  989. }
  990. $form->header;
  991. print qq|
  992. <body>
  993. <form method=post action=$form->{script}>
  994. |;
  995. $form->hide_form(
  996. "id", "type",
  997. "old$form->{vc}", "$form->{vc}_id",
  998. "orphaned", "vc",
  999. "title"
  1000. );
  1001. print qq|
  1002. <table width=100%>
  1003. <tr>
  1004. <th class=listtop>$form->{title}</th>
  1005. </tr>
  1006. <tr height="5"></tr>
  1007. <tr>
  1008. <td>
  1009. <table>
  1010. <tr>
  1011. <th align=right>| . $locale->text('Number') . qq|</th>
  1012. <td><input name=projectnumber size=20 value="$form->{projectnumber}"></td>
  1013. <th align=right>| . $locale->text('Description') . qq|</th>
  1014. <td>$description</td>
  1015. </tr>
  1016. $name
  1017. <tr>
  1018. <th align=right>| . $locale->text('Startdate') . qq|</th>
  1019. <td><input class="date" name=startdate size=11 title="($myconfig{dateformat})" value=$form->{startdate}></td>
  1020. <th align=right>| . $locale->text('Enddate') . qq|</th>
  1021. <td><input class="date" name=enddate size=11 title="($myconfig{dateformat})" value=$form->{enddate}></td>
  1022. </tr>
  1023. </table>
  1024. </td>
  1025. </tr>
  1026. <tr>
  1027. <td><hr size=3 noshade></td>
  1028. </tr>
  1029. </table>
  1030. |;
  1031. }
  1032. sub project_footer {
  1033. $form->hide_form(qw(callback path login sessionid));
  1034. %button =
  1035. ( 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1036. );
  1037. if ( $myconfig{acs} !~ /Projects--Add Project/ ) {
  1038. $button{'save'} =
  1039. { ndx => 3, key => 'S', value => $locale->text('Save') };
  1040. if ( $form->{id} && $form->{orphaned} ) {
  1041. $button{'delete'} =
  1042. { ndx => 16, key => 'D', value => $locale->text('Delete') };
  1043. }
  1044. }
  1045. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1046. $form->print_button( \%button, $_ );
  1047. }
  1048. if ( $form->{lynx} ) {
  1049. require "bin/menu.pl";
  1050. &menubar;
  1051. }
  1052. print qq|
  1053. </form>
  1054. </body>
  1055. </html>
  1056. |;
  1057. }
  1058. sub save {
  1059. if ( $form->{translation} ) {
  1060. PE->save_translation( \%myconfig, \%$form );
  1061. $form->redirect( $locale->text('Translations saved!') );
  1062. exit;
  1063. }
  1064. if ( $form->{type} eq 'project' ) {
  1065. if ( $form->{"select$form->{vc}"} ) {
  1066. ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
  1067. $form->{"$form->{vc}"};
  1068. }
  1069. else {
  1070. if ( $form->{"old$form->{vc}"} ne
  1071. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
  1072. {
  1073. if (
  1074. (
  1075. $rv = $form->get_name(
  1076. \%myconfig, $form->{vc}, $form->{startdate}
  1077. )
  1078. ) > 1
  1079. )
  1080. {
  1081. &select_name;
  1082. exit;
  1083. }
  1084. if ( $rv == 1 ) {
  1085. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  1086. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  1087. $form->{"old$form->{vc}"} =
  1088. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  1089. }
  1090. }
  1091. }
  1092. PE->save_project( \%myconfig, \%$form );
  1093. $form->redirect( $locale->text('Project saved!') );
  1094. }
  1095. if ( $form->{type} eq 'partsgroup' ) {
  1096. $form->isblank( "partsgroup", $locale->text('Group missing!') );
  1097. PE->save_partsgroup( \%myconfig, \%$form );
  1098. $form->redirect( $locale->text('Group saved!') );
  1099. }
  1100. if ( $form->{type} eq 'pricegroup' ) {
  1101. $form->isblank( "pricegroup", $locale->text('Pricegroup missing!') );
  1102. PE->save_pricegroup( \%myconfig, \%$form );
  1103. $form->redirect( $locale->text('Pricegroup saved!') );
  1104. }
  1105. if ( $form->{type} eq 'job' ) {
  1106. if ( $form->{"select$form->{vc}"} ) {
  1107. ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
  1108. $form->{"$form->{vc}"};
  1109. }
  1110. else {
  1111. if ( $form->{"old$form->{vc}"} ne
  1112. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
  1113. {
  1114. if (
  1115. (
  1116. $rv = $form->get_name(
  1117. \%myconfig, $form->{vc}, $form->{startdate}
  1118. )
  1119. ) > 1
  1120. )
  1121. {
  1122. &select_name;
  1123. exit;
  1124. }
  1125. if ( $rv == 1 ) {
  1126. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  1127. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  1128. $form->{"old$form->{vc}"} =
  1129. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  1130. }
  1131. }
  1132. }
  1133. PE->save_job( \%myconfig, \%$form );
  1134. $form->redirect( $locale->text('Job saved!') );
  1135. }
  1136. }
  1137. sub delete {
  1138. if ( $form->{translation} ) {
  1139. PE->delete_translation( \%myconfig, \%$form );
  1140. $form->redirect( $locale->text('Translation deleted!') );
  1141. }
  1142. else {
  1143. if ( $form->{type} eq 'project' ) {
  1144. PE->delete_project( \%myconfig, \%$form );
  1145. $form->redirect( $locale->text('Project deleted!') );
  1146. }
  1147. if ( $form->{type} eq 'job' ) {
  1148. PE->delete_job( \%myconfig, \%$form );
  1149. $form->redirect( $locale->text('Job deleted!') );
  1150. }
  1151. if ( $form->{type} eq 'partsgroup' ) {
  1152. PE->delete_partsgroup( \%myconfig, \%$form );
  1153. $form->redirect( $locale->text('Group deleted!') );
  1154. }
  1155. if ( $form->{type} eq 'pricegroup' ) {
  1156. PE->delete_pricegroup( \%myconfig, \%$form );
  1157. $form->redirect( $locale->text('Pricegroup deleted!') );
  1158. }
  1159. }
  1160. }
  1161. sub partsgroup_report {
  1162. $form->{partsgroup} = $form->unescape( $form->{partsgroup} );
  1163. PE->partsgroups( \%myconfig, \%$form );
  1164. $href =
  1165. "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1166. $form->sort_order();
  1167. $callback =
  1168. "$form->{script}?action=partsgroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1169. if ( $form->{status} eq 'all' ) {
  1170. $option = $locale->text('All');
  1171. }
  1172. if ( $form->{status} eq 'orphaned' ) {
  1173. $option .= $locale->text('Orphaned');
  1174. }
  1175. if ( $form->{partsgroup} ) {
  1176. $callback .= "&partsgroup=$form->{partsgroup}";
  1177. $option .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
  1178. }
  1179. @column_index = $form->sort_columns(qw(partsgroup));
  1180. $column_header{partsgroup} =
  1181. qq|<th><a class=listheading href=$href&sort=partsgroup width=90%>|
  1182. . $locale->text('Group')
  1183. . qq|</a></th>|;
  1184. $form->{title} = $locale->text('Groups');
  1185. $form->header;
  1186. print qq|
  1187. <body>
  1188. <table width=100%>
  1189. <tr>
  1190. <th class=listtop>$form->{title}</th>
  1191. </tr>
  1192. <tr height="5"></tr>
  1193. <tr>
  1194. <td>$option</td>
  1195. </tr>
  1196. <tr>
  1197. <td>
  1198. <table width=100%>
  1199. <tr class=listheading>
  1200. |;
  1201. for (@column_index) { print "$column_header{$_}\n" }
  1202. print qq|
  1203. </tr>
  1204. |;
  1205. # escape callback
  1206. $form->{callback} = $callback;
  1207. # escape callback for href
  1208. $callback = $form->escape($callback);
  1209. foreach $ref ( @{ $form->{item_list} } ) {
  1210. $i++;
  1211. $i %= 2;
  1212. print qq|
  1213. <tr valign=top class=listrow$i>
  1214. |;
  1215. $column_data{partsgroup} =
  1216. qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{partsgroup}</td>|;
  1217. for (@column_index) { print "$column_data{$_}\n" }
  1218. print "
  1219. </tr>
  1220. ";
  1221. }
  1222. $i = 1;
  1223. if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) {
  1224. $button{'Goods & Services--Add Group'}{code} =
  1225. qq|<button class="submit" type="submit" name="action" value="add_group">|
  1226. . $locale->text('Add Group')
  1227. . qq|</button> |;
  1228. $button{'Goods & Services--Add Group'}{order} = $i++;
  1229. foreach $item ( split /;/, $myconfig{acs} ) {
  1230. delete $button{$item};
  1231. }
  1232. }
  1233. print qq|
  1234. </table>
  1235. </td>
  1236. </tr>
  1237. <tr>
  1238. <td><hr size=3 noshade></td>
  1239. </tr>
  1240. </table>
  1241. <br>
  1242. <form method=post action=$form->{script}>
  1243. |;
  1244. $form->hide_form(qw(callback type path login sessionid));
  1245. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1246. print $item->{code};
  1247. }
  1248. if ( $form->{lynx} ) {
  1249. require "bin/menu.pl";
  1250. &menubar;
  1251. }
  1252. print qq|
  1253. </form>
  1254. </body>
  1255. </html>
  1256. |;
  1257. }
  1258. sub partsgroup_header {
  1259. $form->{action} =~ s/_.*//;
  1260. $form->{title} = $locale->text( ucfirst $form->{action} . " Group" );
  1261. # $locale->text('Add Group')
  1262. # $locale->text('Edit Group')
  1263. $form->{partsgroup} = $form->quote( $form->{partsgroup} );
  1264. $form->header;
  1265. print qq|
  1266. <body>
  1267. <form method=post action=$form->{script}>
  1268. <input type=hidden name=id value=$form->{id}>
  1269. <input type=hidden name=type value=$form->{type}>
  1270. <table width=100%>
  1271. <tr>
  1272. <th class=listtop>$form->{title}</th>
  1273. </tr>
  1274. <tr height="5"></tr>
  1275. <tr>
  1276. <td>
  1277. <table width=100%>
  1278. <tr>
  1279. <th align=right>| . $locale->text('Group') . qq|</th>
  1280. <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
  1281. </tr>
  1282. </table>
  1283. </td>
  1284. </tr>
  1285. <tr>
  1286. <td colspan=2><hr size=3 noshade></td>
  1287. </tr>
  1288. </table>
  1289. |;
  1290. }
  1291. sub partsgroup_footer {
  1292. $form->hide_form(qw(callback path login sessionid));
  1293. if ( $myconfig{acs} !~ /Goods \& Services--Add Group/ ) {
  1294. print qq|
  1295. <button type="submit" class="submit" name="action" value="save">|
  1296. . $locale->text('Save')
  1297. . qq|</button>
  1298. |;
  1299. if ( $form->{id} && $form->{orphaned} ) {
  1300. print qq|
  1301. <button type="submit" class="submit" name="action" value="delete">|
  1302. . $locale->text('Delete')
  1303. . qq|</button>|;
  1304. }
  1305. }
  1306. if ( $form->{lynx} ) {
  1307. require "bin/menu.pl";
  1308. &menubar;
  1309. }
  1310. print qq|
  1311. </form>
  1312. </body>
  1313. </html>
  1314. |;
  1315. }
  1316. sub pricegroup_report {
  1317. $form->{pricegroup} = $form->unescape( $form->{pricegroup} );
  1318. PE->pricegroups( \%myconfig, \%$form );
  1319. $href =
  1320. "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1321. $form->sort_order();
  1322. $callback =
  1323. "$form->{script}?action=pricegroup_report&direction=$form->{direction}&oldsort=$form->{oldsort}&type=$form->{type}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&status=$form->{status}";
  1324. if ( $form->{status} eq 'all' ) {
  1325. $option = $locale->text('All');
  1326. }
  1327. if ( $form->{status} eq 'orphaned' ) {
  1328. $option .= $locale->text('Orphaned');
  1329. }
  1330. if ( $form->{pricegroup} ) {
  1331. $callback .= "&pricegroup=$form->{pricegroup}";
  1332. $option .=
  1333. "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
  1334. }
  1335. @column_index = $form->sort_columns(qw(pricegroup));
  1336. $column_header{pricegroup} =
  1337. qq|<th><a class=listheading href=$href&sort=pricegroup width=90%>|
  1338. . $locale->text('Pricegroup')
  1339. . qq|</th>|;
  1340. $form->{title} = $locale->text('Pricegroups');
  1341. $form->header;
  1342. print qq|
  1343. <body>
  1344. <table width=100%>
  1345. <tr>
  1346. <th class=listtop>$form->{title}</th>
  1347. </tr>
  1348. <tr height="5"></tr>
  1349. <tr>
  1350. <td>$option</td>
  1351. </tr>
  1352. <tr>
  1353. <td>
  1354. <table width=100%>
  1355. <tr class=listheading>
  1356. |;
  1357. for (@column_index) { print "$column_header{$_}\n" }
  1358. print qq|
  1359. </tr>
  1360. |;
  1361. # escape callback
  1362. $form->{callback} = $callback;
  1363. # escape callback for href
  1364. $callback = $form->escape($callback);
  1365. foreach $ref ( @{ $form->{item_list} } ) {
  1366. $i++;
  1367. $i %= 2;
  1368. print qq|
  1369. <tr valign=top class=listrow$i>
  1370. |;
  1371. $column_data{pricegroup} =
  1372. qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{pricegroup}</td>|;
  1373. for (@column_index) { print "$column_data{$_}\n" }
  1374. print "
  1375. </tr>
  1376. ";
  1377. }
  1378. $i = 1;
  1379. if ( $myconfig{acs} !~ /Goods \& Services--Goods \& Services/ ) {
  1380. $button{'Goods & Services--Add Pricegroup'}{code} =
  1381. qq|<button class="submit" type="submit" name="action" value="add_pricegroup">|
  1382. . $locale->text('Add Pricegroup')
  1383. . qq|</button> |;
  1384. $button{'Goods & Services--Add Pricegroup'}{order} = $i++;
  1385. foreach $item ( split /;/, $myconfig{acs} ) {
  1386. delete $button{$item};
  1387. }
  1388. }
  1389. print qq|
  1390. </table>
  1391. </td>
  1392. </tr>
  1393. <tr>
  1394. <td><hr size=3 noshade></td>
  1395. </tr>
  1396. </table>
  1397. <br>
  1398. <form method=post action=$form->{script}>
  1399. |;
  1400. $form->hide_form(qw(callback type path login sessionid));
  1401. foreach $item ( sort { $a->{order} <=> $b->{order} } %button ) {
  1402. print $item->{code};
  1403. }
  1404. if ( $form->{lynx} ) {
  1405. require "bin/menu.pl";
  1406. &menubar;
  1407. }
  1408. print qq|
  1409. </form>
  1410. </body>
  1411. </html>
  1412. |;
  1413. }
  1414. sub pricegroup_header {
  1415. $form->{title} = $locale->text( ucfirst $form->{action} . " Pricegroup" );
  1416. # $locale->text('Add Pricegroup')
  1417. # $locale->text('Edit Pricegroup')
  1418. $form->{pricegroup} = $form->quote( $form->{pricegroup} );
  1419. $form->header;
  1420. print qq|
  1421. <body>
  1422. <form method=post action=$form->{script}>
  1423. <input type=hidden name=id value=$form->{id}>
  1424. <input type=hidden name=type value=$form->{type}>
  1425. <table width=100%>
  1426. <tr>
  1427. <th class=listtop>$form->{title}</th>
  1428. </tr>
  1429. <tr height="5"></tr>
  1430. <tr>
  1431. <td>
  1432. <table width=100%>
  1433. <tr>
  1434. <th align=right>| . $locale->text('Pricegroup') . qq|</th>
  1435. <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
  1436. </tr>
  1437. </table>
  1438. </td>
  1439. </tr>
  1440. <tr>
  1441. <td colspan=2><hr size=3 noshade></td>
  1442. </tr>
  1443. </table>
  1444. |;
  1445. }
  1446. sub pricegroup_footer {
  1447. $form->hide_form(qw(callback path login sessionid));
  1448. if ( $myconfig{acs} !~ /Goods \& Services--Add Pricegroup/ ) {
  1449. print qq|
  1450. <button type="submit" class="submit" name="action" value="save">|
  1451. . $locale->text('Save')
  1452. . qq|</button>
  1453. |;
  1454. if ( $form->{id} && $form->{orphaned} ) {
  1455. print qq|
  1456. <button type="submit" class="submit" name="action" value="delete">|
  1457. . $locale->text('Delete')
  1458. . qq|</button>|;
  1459. }
  1460. }
  1461. if ( $form->{lynx} ) {
  1462. require "bin/menu.pl";
  1463. &menubar;
  1464. }
  1465. print qq|
  1466. </form>
  1467. </body>
  1468. </html>
  1469. |;
  1470. }
  1471. sub translation {
  1472. if ( $form->{translation} eq 'description' ) {
  1473. $form->{title} = $locale->text('Description Translations');
  1474. $sort = qq|<input type=hidden name=sort value=partnumber>|;
  1475. $form->{number} = "partnumber";
  1476. $number = qq|
  1477. <tr>
  1478. <th align=right nowrap>| . $locale->text('Number') . qq|</th>
  1479. <td><input name=partnumber size=20></td>
  1480. </tr>
  1481. |;
  1482. }
  1483. if ( $form->{translation} eq 'partsgroup' ) {
  1484. $form->{title} = $locale->text('Group Translations');
  1485. $sort = qq|<input type=hidden name=sort value=partsgroup>|;
  1486. }
  1487. if ( $form->{translation} eq 'project' ) {
  1488. $form->{title} = $locale->text('Project Description Translations');
  1489. $form->{number} = "projectnumber";
  1490. $sort = qq|<input type=hidden name=sort value=projectnumber>|;
  1491. $number = qq|
  1492. <tr>
  1493. <th align=right nowrap>| . $locale->text('Project Number') . qq|</th>
  1494. <td><input name=projectnumber size=20></td>
  1495. </tr>
  1496. |;
  1497. }
  1498. $form->header;
  1499. print qq|
  1500. <body>
  1501. <form method=post action=$form->{script}>
  1502. |;
  1503. $form->hide_form(qw(translation title number));
  1504. print qq|
  1505. <table width="100%">
  1506. <tr><th class=listtop>$form->{title}</th></tr>
  1507. <tr height="5"></tr>
  1508. <tr valign=top>
  1509. <td>
  1510. <table>
  1511. $number
  1512. <tr>
  1513. <th align=right nowrap>| . $locale->text('Description') . qq|</th>
  1514. <td colspan=3><input name=description size=40></td>
  1515. </tr>
  1516. </table>
  1517. </td>
  1518. </tr>
  1519. <tr><td><hr size=3 noshade></td></tr>
  1520. </table>
  1521. <input type=hidden name=nextsub value=list_translations>
  1522. $sort
  1523. |;
  1524. $form->hide_form(qw(path login sessionid));
  1525. print qq|
  1526. <br>
  1527. <button class="submit" type="submit" name="action" value="continue">|
  1528. . $locale->text('Continue')
  1529. . qq|</button>
  1530. </form>
  1531. </body>
  1532. </html>
  1533. |;
  1534. }
  1535. sub list_translations {
  1536. $title = $form->escape( $form->{title}, 1 );
  1537. $callback =
  1538. "$form->{script}?action=list_translations&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&translation=$form->{translation}&number=$form->{number}&title=$title";
  1539. if ( $form->{"$form->{number}"} ) {
  1540. $callback .= qq|&$form->{number}=$form->{"$form->{number}"}|;
  1541. $option .=
  1542. $locale->text('Number') . qq| : $form->{"$form->{number}"}<br>|;
  1543. }
  1544. if ( $form->{description} ) {
  1545. $callback .= "&description=$form->{description}";
  1546. $description = $form->{description};
  1547. $description =~ s/\r?\n/<br>/g;
  1548. $option .=
  1549. $locale->text('Description') . qq| : $form->{description}<br>|;
  1550. }
  1551. if ( $form->{translation} eq 'partsgroup' ) {
  1552. @column_index = qw(description language translation);
  1553. $form->{sort} = "";
  1554. }
  1555. else {
  1556. @column_index =
  1557. $form->sort_columns( "$form->{number}", "description", "language",
  1558. "translation" );
  1559. }
  1560. &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
  1561. $callback .= "&direction=$form->{direction}&oldsort=$form->{oldsort}";
  1562. $href = $callback;
  1563. $form->sort_order();
  1564. $callback =~ s/(direction=).*\&{1}/$1$form->{direction}\&/;
  1565. $column_header{"$form->{number}"} =
  1566. qq|<th nowrap><a class=listheading href=$href&sort=$form->{number}>|
  1567. . $locale->text('Number')
  1568. . qq|</a></th>|;
  1569. $column_header{description} =
  1570. qq|<th nowrap width=40%><a class=listheading href=$href&sort=description>|
  1571. . $locale->text('Description')
  1572. . qq|</a></th>|;
  1573. $column_header{language} =
  1574. qq|<th nowrap class=listheading>|
  1575. . $locale->text('Language')
  1576. . qq|</a></th>|;
  1577. $column_header{translation} =
  1578. qq|<th nowrap width=40% class=listheading>|
  1579. . $locale->text('Translation')
  1580. . qq|</a></th>|;
  1581. $form->header;
  1582. print qq|
  1583. <body>
  1584. <table width=100%>
  1585. <tr>
  1586. <th class=listtop>$form->{title}</th>
  1587. </tr>
  1588. <tr height="5"></tr>
  1589. <tr><td>$option</td></tr>
  1590. <tr>
  1591. <td>
  1592. <table width=100%>
  1593. <tr class=listheading>
  1594. |;
  1595. for (@column_index) { print "\n$column_header{$_}" }
  1596. print qq|
  1597. </tr>
  1598. |;
  1599. # add order to callback
  1600. $form->{callback} = $callback .= "&sort=$form->{sort}";
  1601. # escape callback for href
  1602. $callback = $form->escape($callback);
  1603. if ( @{ $form->{translations} } ) {
  1604. $sameitem = $form->{translations}->[0]->{ $form->{sort} };
  1605. }
  1606. foreach $ref ( @{ $form->{translations} } ) {
  1607. $ref->{description} =~ s/\r?\n/<br>/g;
  1608. for (@column_index) { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" }
  1609. $column_data{description} =
  1610. "<td><a href=$form->{script}?action=edit_translation&translation=$form->{translation}&number=$form->{number}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}&nbsp;</a></td>";
  1611. $i++;
  1612. $i %= 2;
  1613. print "<tr class=listrow$i>";
  1614. for (@column_index) { print "\n$column_data{$_}" }
  1615. print qq|
  1616. </tr>
  1617. |;
  1618. }
  1619. print qq|
  1620. </table>
  1621. </td>
  1622. </tr>
  1623. <tr><td><hr size=3 noshade></td></tr>
  1624. </table>
  1625. |;
  1626. print qq|
  1627. <br>
  1628. <form method=post action=$form->{script}>
  1629. <input name=callback type=hidden value="$form->{callback}">
  1630. |;
  1631. $form->hide_form(qw(path login sessionid));
  1632. if ( $form->{lynx} ) {
  1633. require "bin/menu.pl";
  1634. &menubar;
  1635. }
  1636. print qq|
  1637. </form>
  1638. </body>
  1639. </html>
  1640. |;
  1641. }
  1642. sub edit_translation {
  1643. &{"PE::$form->{translation}_translations"}( "", \%myconfig, \%$form );
  1644. $form->error( $locale->text('Languages not defined!') )
  1645. unless @{ $form->{all_language} };
  1646. $form->{selectlanguage} = qq|<option>\n|;
  1647. for ( @{ $form->{all_language} } ) {
  1648. $form->{selectlanguage} .=
  1649. qq|<option value="$_->{code}">$_->{description}\n|;
  1650. }
  1651. $form->{"$form->{number}"} =
  1652. $form->{translations}->[0]->{"$form->{number}"};
  1653. $form->{description} = $form->{translations}->[0]->{description};
  1654. $form->{description} =~ s/\r?\n/<br>/g;
  1655. shift @{ $form->{translations} };
  1656. $i = 1;
  1657. foreach $row ( @{ $form->{translations} } ) {
  1658. $form->{"language_code_$i"} = $row->{code};
  1659. $form->{"translation_$i"} = $row->{translation};
  1660. $i++;
  1661. }
  1662. $form->{translation_rows} = $i - 1;
  1663. $form->{title} = $locale->text('Edit Description Translations');
  1664. &translation_header;
  1665. &translation_footer;
  1666. }
  1667. sub translation_header {
  1668. $form->{translation_rows}++;
  1669. $form->{selectlanguage} = $form->unescape( $form->{selectlanguage} );
  1670. for $i ( 1 .. $form->{translation_rows} ) {
  1671. $form->{"selectlanguage_$i"} = $form->{selectlanguage};
  1672. if ( $form->{"language_code_$i"} ) {
  1673. $form->{"selectlanguage_$i"} =~
  1674. s/(<option value="\Q$form->{"language_code_$i"}\E")/$1 selected/;
  1675. }
  1676. }
  1677. $form->{selectlanguage} = $form->escape( $form->{selectlanguage}, 1 );
  1678. $form->header;
  1679. print qq|
  1680. <body>
  1681. <form method=post action=$form->{script}>
  1682. <input type=hidden name=$form->{number} value="|
  1683. . $form->quote( $form->{"$form->{number}"} ) . qq|">
  1684. <input type=hidden name=description value="|
  1685. . $form->quote( $form->{description} ) . qq|">
  1686. |;
  1687. $form->hide_form(
  1688. qw(id trans_id selectlanguage translation_rows number translation title)
  1689. );
  1690. print qq|
  1691. <table width="100%">
  1692. <tr><th class=listtop>$form->{title}</th></tr>
  1693. <tr height="5"></tr>
  1694. <tr valign=top>
  1695. <td>
  1696. <table width=100%>
  1697. <tr>
  1698. <td align=left>$form->{"$form->{number}"}</th>
  1699. <td align=left>$form->{description}</th>
  1700. </tr>
  1701. <tr>
  1702. <tr>
  1703. <th class=listheading>| . $locale->text('Language') . qq|</th>
  1704. <th class=listheading>| . $locale->text('Translation') . qq|</th>
  1705. </tr>
  1706. |;
  1707. for $i ( 1 .. $form->{translation_rows} ) {
  1708. if ( ( $rows = $form->numtextrows( $form->{"translation_$i"}, 40 ) ) >
  1709. 1 )
  1710. {
  1711. $translation =
  1712. qq|<textarea name="translation_$i" rows=$rows cols=40 wrap=soft>$form->{"translation_$i"}</textarea>|;
  1713. }
  1714. else {
  1715. $translation =
  1716. qq|<input name="translation_$i" size=40 value="$form->{"translation_$i"}">|;
  1717. }
  1718. print qq|
  1719. <tr valign=top>
  1720. <td><select name="language_code_$i">$form->{"selectlanguage_$i"}</select></td>
  1721. <td>$translation</td>
  1722. </tr>
  1723. |;
  1724. }
  1725. print qq|
  1726. </table>
  1727. </td>
  1728. </tr>
  1729. <tr>
  1730. <td><hr size=3 noshade></td>
  1731. </tr>
  1732. </table>
  1733. |;
  1734. }
  1735. sub translation_footer {
  1736. $form->hide_form(qw(path login sessionid callback));
  1737. %button = (
  1738. 'update' => { ndx => 1, key => 'U', value => $locale->text('Update') },
  1739. 'save' => { ndx => 3, key => 'S', value => $locale->text('Save') },
  1740. 'delete' => { ndx => 16, key => 'D', value => $locale->text('Delete') },
  1741. );
  1742. if ( !$form->{trans_id} ) {
  1743. delete $button{'delete'};
  1744. }
  1745. for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) {
  1746. $form->print_button( \%button, $_ );
  1747. }
  1748. if ( $form->{lynx} ) {
  1749. require "bin/menu.pl";
  1750. &menubar;
  1751. }
  1752. print qq|
  1753. </form>
  1754. </body>
  1755. </html>
  1756. |;
  1757. }
  1758. sub update {
  1759. if ( $form->{translation} ) {
  1760. @flds = qw(language translation);
  1761. $count = 0;
  1762. @a = ();
  1763. for $i ( 1 .. $form->{translation_rows} ) {
  1764. if ( $form->{"language_code_$i"} ne "" ) {
  1765. push @a, {};
  1766. $j = $#a;
  1767. for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
  1768. $count++;
  1769. }
  1770. }
  1771. $form->redo_rows( \@flds, \@a, $count, $form->{translation_rows} );
  1772. $form->{translation_rows} = $count;
  1773. &translation_header;
  1774. &translation_footer;
  1775. exit;
  1776. }
  1777. if ( $form->{type} =~ /(job|project)/ ) {
  1778. # $locale->text('Customer not on file!')
  1779. # $locale->text('Vendor not on file!')
  1780. for (qw(production listprice sellprice weight)) {
  1781. $form->{$_} = $form->parse_amount( \%myconfig, $form->{$_} );
  1782. }
  1783. $form->{projectnumber} =
  1784. $form->update_defaults( \%myconfig, "projectnumber" )
  1785. unless $form->{projectnumber};
  1786. if ( $form->{"select$form->{vc}"} ) {
  1787. if ( $form->{startdate} ne $form->{oldstartdate}
  1788. || $form->{enddate} ne $form->{oldenddate} )
  1789. {
  1790. PE->get_customer( \%myconfig, \%$form );
  1791. if ( @{ $form->{"all_$form->{vc}"} } ) {
  1792. $form->{"select$form->{vc}"} = qq|<option>\n|;
  1793. for ( @{ $form->{"all_$form->{vc}"} } ) {
  1794. $form->{"select$form->{vc}"} .=
  1795. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1796. }
  1797. }
  1798. }
  1799. $form->{"old$form->{vc}"} = $form->{"$form->{vc}"};
  1800. ( $null, $form->{"$form->{vc}_id"} ) = split /--/,
  1801. $form->{"$form->{vc}"};
  1802. }
  1803. else {
  1804. if ( $form->{"old$form->{vc}"} ne
  1805. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}| )
  1806. {
  1807. if (
  1808. (
  1809. $rv = $form->get_name(
  1810. \%myconfig, $form->{vc}, $form->{startdate}
  1811. )
  1812. ) > 1
  1813. )
  1814. {
  1815. &select_name;
  1816. exit;
  1817. }
  1818. if ( $rv == 1 ) {
  1819. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  1820. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  1821. $form->{"old$form->{vc}"} =
  1822. qq|$form->{"$form->{vc}"}--$form->{"$form->{vc}_id"}|;
  1823. }
  1824. else {
  1825. $msg = ucfirst $form->{vc} . " not on file!";
  1826. $form->error( $locale->text($msg) );
  1827. }
  1828. }
  1829. }
  1830. }
  1831. &display_form;
  1832. }
  1833. sub select_name {
  1834. $label = ucfirst $form->{vc};
  1835. @column_index = qw(ndx name address);
  1836. $column_data{ndx} = qq|<th>&nbsp;</th>|;
  1837. $column_data{name} =
  1838. qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
  1839. $column_data{address} =
  1840. qq|<th class=listheading colspan=5>|
  1841. . $locale->text('Address')
  1842. . qq|</th>|;
  1843. $form->header;
  1844. $title = $locale->text('Select from one of the names below');
  1845. print qq|
  1846. <body>
  1847. <form method=post action=$form->{script}>
  1848. <table width=100%>
  1849. <tr>
  1850. <th class=listtop>$title</th>
  1851. </tr>
  1852. <tr space=5></tr>
  1853. <tr>
  1854. <td>
  1855. <table width=100%>
  1856. <tr class=listheading>|;
  1857. for (@column_index) { print "\n$column_data{$_}" }
  1858. print qq|
  1859. </tr>
  1860. |;
  1861. @column_index = qw(ndx name address city state zipcode country);
  1862. my $i = 0;
  1863. foreach $ref ( @{ $form->{name_list} } ) {
  1864. $checked = ( $i++ ) ? "" : "checked";
  1865. $ref->{name} = $form->quote( $ref->{name} );
  1866. $column_data{ndx} =
  1867. qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
  1868. $column_data{name} =
  1869. qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
  1870. $column_data{address} = qq|<td>$ref->{address1} $ref->{address2}</td>|;
  1871. for (qw(city state zipcode country)) {
  1872. $column_data{$_} = qq|<td>$ref->{$_}&nbsp;</td>|;
  1873. }
  1874. $j++;
  1875. $j %= 2;
  1876. print qq|
  1877. <tr class=listrow$j>|;
  1878. for (@column_index) { print "\n$column_data{$_}" }
  1879. print qq|
  1880. </tr>
  1881. <input name="new_id_$i" type=hidden value=$ref->{id}>
  1882. |;
  1883. }
  1884. print qq|
  1885. </table>
  1886. </td>
  1887. </tr>
  1888. <tr>
  1889. <td><hr size=3 noshade></td>
  1890. </tr>
  1891. </table>
  1892. <input name=lastndx type=hidden value=$i>
  1893. |;
  1894. # delete variables
  1895. for (qw(action nextsub name_list)) { delete $form->{$_} }
  1896. $form->hide_form;
  1897. print qq|
  1898. <input type="hidden" name="nextsub" value="name_selected">
  1899. <br>
  1900. <button class="submit" type="submit" name="action" value="continue">|
  1901. . $locale->text('Continue')
  1902. . qq|</button>
  1903. </form>
  1904. </body>
  1905. </html>
  1906. |;
  1907. }
  1908. sub name_selected {
  1909. # replace the variable with the one checked
  1910. # index for new item
  1911. $i = $form->{ndx};
  1912. $form->{ $form->{vc} } = $form->{"new_name_$i"};
  1913. $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
  1914. $form->{"old$form->{vc}"} =
  1915. qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
  1916. # delete all the new_ variables
  1917. for $i ( 1 .. $form->{lastndx} ) {
  1918. for (qw(id name)) { delete $form->{"new_${_}_$i"} }
  1919. }
  1920. for (qw(ndx lastndx nextsub)) { delete $form->{$_} }
  1921. &display_form;
  1922. }
  1923. sub display_form {
  1924. &{"$form->{type}_header"};
  1925. &{"$form->{type}_footer"};
  1926. }
  1927. sub continue { &{ $form->{nextsub} } }
  1928. sub add_group { &add }
  1929. sub add_project { &add }
  1930. sub add_job { &add }
  1931. sub add_pricegroup { &add }
  1932. sub project_sales_order {
  1933. PE->project_sales_order( \%myconfig, \%$form );
  1934. if ( @{ $form->{all_years} } ) {
  1935. $form->{selectaccountingyear} = "<option>\n";
  1936. for ( @{ $form->{all_years} } ) {
  1937. $form->{selectaccountingyear} .= qq|<option>$_\n|;
  1938. }
  1939. $form->{selectaccountingmonth} = "<option>\n";
  1940. for ( sort keys %{ $form->{all_month} } ) {
  1941. $form->{selectaccountingmonth} .=
  1942. qq|<option value=$_>|
  1943. . $locale->text( $form->{all_month}{$_} ) . qq|\n|;
  1944. }
  1945. $selectfrom = qq|
  1946. <tr>
  1947. <th align=right>| . $locale->text('Period') . qq|</th>
  1948. <td colspan=3>
  1949. <select name=month>$form->{selectaccountingmonth}</select>
  1950. <select name=year>$form->{selectaccountingyear}</select>
  1951. <input name=interval class=radio type=radio value=0 checked>&nbsp;|
  1952. . $locale->text('Current') . qq|
  1953. <input name=interval class=radio type=radio value=1>&nbsp;|
  1954. . $locale->text('Month') . qq|
  1955. <input name=interval class=radio type=radio value=3>&nbsp;|
  1956. . $locale->text('Quarter') . qq|
  1957. <input name=interval class=radio type=radio value=12>&nbsp;|
  1958. . $locale->text('Year') . qq|
  1959. </td>
  1960. </tr>
  1961. |;
  1962. }
  1963. $fromto = qq|
  1964. <tr>
  1965. <th align=right nowrap>| . $locale->text('Transaction Dates') . qq|</th>
  1966. <td>|
  1967. . $locale->text('From')
  1968. . qq| <input class="date" name=transdatefrom size=11 title="$myconfig{dateformat}">
  1969. |
  1970. . $locale->text('To')
  1971. . qq| <input class="date" name=transdateto size=11 title="$myconfig{dateformat}"></td>
  1972. </tr>
  1973. $selectfrom
  1974. |;
  1975. if ( @{ $form->{all_project} } ) {
  1976. $form->{selectprojectnumber} = "<option>\n";
  1977. for ( @{ $form->{all_project} } ) {
  1978. $form->{selectprojectnumber} .=
  1979. qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n|;
  1980. }
  1981. }
  1982. else {
  1983. $form->error( $locale->text('No open Projects!') );
  1984. }
  1985. if ( @{ $form->{all_employee} } ) {
  1986. $form->{selectemployee} = "<option>\n";
  1987. for ( @{ $form->{all_employee} } ) {
  1988. $form->{selectemployee} .=
  1989. qq|<option value="$_->{name}--$_->{id}">$_->{name}\n|;
  1990. }
  1991. $employee = qq|
  1992. <tr>
  1993. <th align=right nowrap>| . $locale->text('Employee') . qq|</th>
  1994. <td><select name=employee>$form->{selectemployee}</select></td>
  1995. </tr>
  1996. |;
  1997. }
  1998. $form->{title} = $locale->text('Generate Sales Orders');
  1999. $form->{vc} = "customer";
  2000. $form->{type} = "sales_order";
  2001. $form->header;
  2002. print qq|
  2003. <body>
  2004. <form method=post action=$form->{script}>
  2005. <table width=100%>
  2006. <tr>
  2007. <th class=listtop>$form->{title}</th>
  2008. </tr>
  2009. <tr height="5"></tr>
  2010. <tr valign=top>
  2011. <td>
  2012. <table>
  2013. <tr>
  2014. <th align=right>| . $locale->text('Project') . qq|</th>
  2015. <td colspan=3><select name=projectnumber>$form->{selectprojectnumber}</select></td>
  2016. </tr>
  2017. $employee
  2018. $fromto
  2019. <tr>
  2020. <th></th>
  2021. <td><input name=summary type=radio class=radio value=1 checked> |
  2022. . $locale->text('Summary') . qq|
  2023. <input name=summary type=radio class=radio value=0> |
  2024. . $locale->text('Detail') . qq|
  2025. </td>
  2026. </tr>
  2027. </table>
  2028. </td>
  2029. </tr>
  2030. <tr>
  2031. <td><hr size=3 noshade></td>
  2032. </tr>
  2033. </table>
  2034. |;
  2035. $form->{nextsub} = "project_jcitems_list";
  2036. $form->hide_form(qw(path login sessionid nextsub type vc));
  2037. print qq|
  2038. <button type="submit" class="submit" name="action" value="continue">|
  2039. . $locale->text('Continue')
  2040. . qq|</button>
  2041. </form>
  2042. |;
  2043. if ( $form->{lynx} ) {
  2044. require "bin/menu.pl";
  2045. &menubar;
  2046. }
  2047. print qq|
  2048. </body>
  2049. </html>
  2050. |;
  2051. }
  2052. sub project_jcitems_list {
  2053. $form->{projectnumber} = $form->unescape( $form->{projectnumber} );
  2054. $form->{employee} = $form->unescape( $form->{employee} );
  2055. $form->{callback} = "$form->{script}?action=project_jcitems_list";
  2056. for (
  2057. qw(month year interval summary transdatefrom transdateto login path sessionid nextsub type vc)
  2058. )
  2059. {
  2060. $form->{callback} .= "&$_=$form->{$_}";
  2061. }
  2062. for (qw(employe projectnumber)) {
  2063. $form->{callback} .= "&$_=" . $form->escape( $form->{$_}, 1 );
  2064. }
  2065. PE->get_jcitems( \%myconfig, \%$form );
  2066. # flatten array
  2067. $i = 1;
  2068. foreach $ref ( @{ $form->{jcitems} } ) {
  2069. if ( $form->{summary} ) {
  2070. $thisitem =
  2071. qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
  2072. if ( $thisitem eq $sameitem ) {
  2073. $i--;
  2074. for (qw(qty amount)) { $form->{"${_}_$i"} += $ref->{$_} }
  2075. $form->{"id_$i"} .= " $ref->{id}:$ref->{qty}";
  2076. if ( $form->{"notes_$i"} ) {
  2077. $form->{"notes_$i"} .= qq|\n\n$ref->{notes}|;
  2078. }
  2079. else {
  2080. $form->{"notes_$i"} = $ref->{notes};
  2081. }
  2082. }
  2083. else {
  2084. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  2085. $form->{"checked_$i"} = 1;
  2086. $form->{"$form->{vc}_$i"} = $ref->{ $form->{vc} };
  2087. $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
  2088. }
  2089. $sameitem =
  2090. qq|$ref->{project_id}:$ref->{"$form->{vc}_id"}:$ref->{parts_id}|;
  2091. }
  2092. else {
  2093. for ( keys %$ref ) { $form->{"${_}_$i"} = $ref->{$_} }
  2094. $form->{"checked_$i"} = 1;
  2095. $form->{"id_$i"} = "$ref->{id}:$ref->{qty}";
  2096. }
  2097. $i++;
  2098. }
  2099. $form->{rowcount} = $i - 1;
  2100. for $i ( 1 .. $form->{rowcount} ) {
  2101. for (qw(qty allocated)) {
  2102. $form->{"${_}_$i"} =
  2103. $form->format_amount( \%myconfig, $form->{"${_}_$i"} );
  2104. }
  2105. for (qw(amount sellprice)) {
  2106. $form->{"${_}_$i"} =
  2107. $form->format_amount( \%myconfig, $form->{"${_}_$i"}, 2 );
  2108. }
  2109. }
  2110. &jcitems;
  2111. }
  2112. sub jcitems {
  2113. # $locale->text('Customer')
  2114. # $locale->text('Vendor')
  2115. $vc = ucfirst $form->{vc};
  2116. @column_index = qw(id projectnumber name);
  2117. if ( !$form->{summary} ) {
  2118. push @column_index, qw(transdate);
  2119. }
  2120. push @column_index, qw(partnumber description qty amount);
  2121. $column_header{id} = qq|<th>&nbsp;</th>|;
  2122. $column_header{transdate} =
  2123. qq|<th class=listheading>| . $locale->text('Date') . qq|</th>|;
  2124. $column_header{partnumber} =
  2125. qq|<th class=listheading>|
  2126. . $locale->text('Service Code')
  2127. . qq|<br>|
  2128. . $locale->text('Part Number')
  2129. . qq|</th>|;
  2130. $column_header{projectnumber} =
  2131. qq|<th class=listheading>| . $locale->text('Project Number') . qq|</th>|;
  2132. $column_header{description} =
  2133. qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
  2134. $column_header{name} = qq|<th class=listheading>$vc</th>|;
  2135. $column_header{qty} =
  2136. qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
  2137. $column_header{amount} =
  2138. qq|<th class=listheading>| . $locale->text('Amount') . qq|</th>|;
  2139. if ( $form->{type} eq 'sales_order' ) {
  2140. $form->{title} = $locale->text('Generate Sales Orders');
  2141. }
  2142. $form->header;
  2143. print qq|
  2144. <body>
  2145. <form method=post action=$form->{script}>
  2146. <table width=100%>
  2147. <tr>
  2148. <th class=listtop>$form->{title}</th>
  2149. </tr>
  2150. <tr height="5"></tr>
  2151. <tr>
  2152. <td>
  2153. <table width=100%>
  2154. <tr class=listheading>|;
  2155. for (@column_index) { print "\n$column_header{$_}" }
  2156. print qq|
  2157. </tr>
  2158. |;
  2159. for $i ( 1 .. $form->{rowcount} ) {
  2160. for (@column_index) {
  2161. $column_data{$_} = qq|<td>$form->{"${_}_$i"}</td>|;
  2162. }
  2163. for (qw(qty amount)) {
  2164. $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|;
  2165. }
  2166. $checked = ( $form->{"checked_$i"} ) ? "checked" : "";
  2167. $column_data{id} =
  2168. qq|<td><input name="checked_$i" class=checkbox type=checkbox value="1" $checked></td>|;
  2169. if ( $form->{"$form->{vc}_id_$i"} ) {
  2170. $column_data{name} = qq|<td>$form->{"$form->{vc}_$i"}</td>|;
  2171. $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );
  2172. }
  2173. else {
  2174. $column_data{name} =
  2175. qq|<td><input name="ndx_$i" class=checkbox type=checkbox value="1"></td>|;
  2176. }
  2177. for (qw(projectnumber partnumber description notes)) {
  2178. $form->{"${_}_$i"} = $form->quote( $form->{"${_}_$i"} );
  2179. }
  2180. $form->hide_form( map { "${_}_$i" }
  2181. qw(id project_id parts_id projectnumber transdate partnumber description notes qty amount taxaccounts sellprice)
  2182. );
  2183. $j++;
  2184. $j %= 2;
  2185. print "
  2186. <tr class=listrow$j>";
  2187. for (@column_index) { print "\n$column_data{$_}" }
  2188. print qq|
  2189. </tr>
  2190. |;
  2191. }
  2192. print qq|
  2193. </table>
  2194. </td>
  2195. </tr>
  2196. <tr>
  2197. <td><hr size=3 noshade></td>
  2198. </tr>
  2199. </table>
  2200. <br>
  2201. |;
  2202. $form->hide_form(
  2203. qw(path login sessionid vc nextsub rowcount type currency defaultcurrency taxaccounts summary callback)
  2204. );
  2205. for ( split / /, $form->{taxaccounts} ) { $form->hide_form("${_}_rate") }
  2206. if ( $form->{rowcount} ) {
  2207. print qq|
  2208. <button class="submit" type="submit" name="action" value="generate_sales_orders">|
  2209. . $locale->text('Generate Sales Orders')
  2210. . qq|</button>|;
  2211. print qq|
  2212. <button class="submit" type="submit" name="action" value="select_customer">|
  2213. . $locale->text('Select Customer')
  2214. . qq|</button>|;
  2215. }
  2216. if ( $form->{lynx} ) {
  2217. require "bin/menu.pl";
  2218. &menubar;
  2219. }
  2220. print qq|
  2221. </form>
  2222. </body>
  2223. </html>
  2224. |;
  2225. }
  2226. sub select_customer {
  2227. for ( 1 .. $form->{rowcount} ) {
  2228. last if ( $ok = $form->{"ndx_$_"} );
  2229. }
  2230. $form->error( $locale->text('Nothing selected!') ) unless $ok;
  2231. $label =
  2232. ( $form->{vc} eq 'customer' )
  2233. ? $locale->text('Customer')
  2234. : $locale->text('Vendor');
  2235. $form->header;
  2236. print qq|
  2237. <body onLoad="document.forms[0].$form->{vc}.focus()" />
  2238. <form method=post action=$form->{script}>
  2239. <b>$label</b> <input name=$form->{vc} size=40>
  2240. |;
  2241. $form->{nextsub} = "$form->{vc}_selected";
  2242. $form->{action} = "$form->{vc}_selected";
  2243. $form->hide_form;
  2244. print qq|
  2245. <button class="submit" type="submit" name="action" value="continue">|
  2246. . $locale->text('Continue')
  2247. . qq|</button>
  2248. </form>
  2249. |;
  2250. print qq|
  2251. </body>
  2252. </html>
  2253. |;
  2254. }
  2255. sub customer_selected {
  2256. if (
  2257. (
  2258. $rv = $form->get_name( \%myconfig, $form->{vc}, $form->{startdate} )
  2259. ) > 1
  2260. )
  2261. {
  2262. &select_name( $form->{vc} );
  2263. exit;
  2264. }
  2265. if ( $rv == 1 ) {
  2266. $form->{"$form->{vc}"} = $form->{name_list}[0]->{name};
  2267. $form->{"$form->{vc}_id"} = $form->{name_list}[0]->{id};
  2268. }
  2269. else {
  2270. $msg =
  2271. ( $form->{vc} eq 'customer' )
  2272. ? $locale->text('Customer not on file!')
  2273. : $locale->text('Vendor not on file!');
  2274. $form->error( $locale->text($msg) );
  2275. }
  2276. &display_form;
  2277. }
  2278. sub sales_order_header {
  2279. for ( 1 .. $form->{rowcount} ) {
  2280. if ( $form->{"ndx_$_"} ) {
  2281. $form->{"$form->{vc}_id_$_"} = $form->{"$form->{vc}_id"};
  2282. $form->{"$form->{vc}_$_"} = $form->{"$form->{vc}"};
  2283. }
  2284. }
  2285. }
  2286. sub sales_order_footer { &jcitems }
  2287. sub generate_sales_orders {
  2288. for $i ( 1 .. $form->{rowcount} ) {
  2289. $form->error( $locale->text('Customer missing!') )
  2290. if ( $form->{"checked_$i"} && !$form->{"customer_$i"} );
  2291. }
  2292. for $i ( 1 .. $form->{rowcount} ) {
  2293. if ( $form->{"checked_$i"} ) {
  2294. push @{ $form->{order}{qq|$form->{"customer_id_$i"}|} },
  2295. {
  2296. partnumber => $form->{"partnumber_$i"},
  2297. id => $form->{"parts_id_$i"},
  2298. description => $form->{"description_$i"},
  2299. qty => $form->{"qty_$i"},
  2300. sellprice => $form->{"sellprice_$i"},
  2301. projectnumber => qq|--$form->{"project_id_$i"}|,
  2302. reqdate => $form->{"transdate_$i"},
  2303. taxaccounts => $form->{"taxaccounts_$i"},
  2304. jcitems => $form->{"id_$i"},
  2305. notes => $form->{"notes_$i"},
  2306. };
  2307. }
  2308. }
  2309. $order = new Form;
  2310. $order->{dbh} = $form->{dbh};
  2311. for ( keys %{ $form->{order} } ) {
  2312. for (qw(type vc defaultcurrency login)) { $order->{$_} = $form->{$_} }
  2313. for ( split / /, $form->{taxaccounts} ) {
  2314. $order->{"${_}_rate"} = $form->{"${_}_rate"};
  2315. }
  2316. $i = 0;
  2317. $order->{"$order->{vc}_id"} = $_;
  2318. AA->get_name( \%myconfig, \%$order );
  2319. foreach $ref ( @{ $form->{order}{$_} } ) {
  2320. $i++;
  2321. for ( keys %$ref ) { $order->{"${_}_$i"} = $ref->{$_} }
  2322. $taxaccounts = "";
  2323. for ( split / /, $order->{taxaccounts} ) {
  2324. $taxaccounts .= qq|$_ |
  2325. if ( $_ =~ /$order->{"taxaccounts_$i"}/ );
  2326. }
  2327. $order->{"taxaccounts_$i"} = $taxaccounts;
  2328. }
  2329. $order->{rowcount} = $i;
  2330. for (qw(currency)) { $order->{$_} = $form->{$_} }
  2331. $order->{ordnumber} = $order->update_defaults( \%myconfig, 'sonumber' );
  2332. $order->{transdate} = $order->current_date( \%myconfig );
  2333. $order->{reqdate} = $order->{transdate};
  2334. for (qw(intnotes employee employee_id)) { delete $order->{$_} }
  2335. PE->timecard_get_currency( \%$order );
  2336. if ( OE->save( \%myconfig, \%$order ) ) {
  2337. if ( !PE->allocate_projectitems( \%myconfig, \%$order ) ) {
  2338. OE->delete( \%myconfig, \%$order,
  2339. ${LedgerSMB::Sysconfig::spool} );
  2340. }
  2341. }
  2342. else {
  2343. $order->error( $locale->text('Failed to save order!') );
  2344. }
  2345. for ( keys %$order ) { delete $order->{$_} }
  2346. }
  2347. $form->redirect( $locale->text('Orders generated!') );
  2348. }