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