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