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