3 include_once($path_to_root . "/admin/db/voiding_db.inc");
4 include_once($path_to_root . "/includes/types.inc");
6 //--------------------------------------------------------------------------------------
8 function get_supplier_trans_view_str($type, $trans_no, $label="")
10 global $path_to_root, $use_popup_windows;
13 if ($type == systypes::po())
14 $viewer = "view_po.php";
16 $viewer = "view_supp_invoice.php";
18 $viewer = "view_supp_credit.php";
20 $viewer = "view_supp_payment.php";
22 $viewer = "view_grn.php";
31 if ($use_popup_windows)
32 $preview_str = "<a target='_blank' href='$path_to_root/purchasing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
34 $preview_str = "<a target='_blank' href='$path_to_root/purchasing/view/$viewer?trans_no=$trans_no'>$label</a>";
37 $preview_str = $label;
42 //--------------------------------------------------------------------------------------
44 function get_gl_view_str($type, $trans_no, $label="", $force=false)
46 global $path_to_root, $use_popup_windows;
48 if (!$force && !user_show_gl_info())
53 if ($use_popup_windows)
54 $gl_view = "<a target='_blank' href='$path_to_root/gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
56 $gl_view = "<a target='_blank' href='$path_to_root/gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no'>$label</a>";
61 //--------------------------------------------------------------------------------------
63 function get_gl_view_str_cell($type, $trans_no, $label="")
65 $str = get_gl_view_str($type, $trans_no, $label);
67 return "<td>$str</td>";
70 //--------------------------------------------------------------------------------------
72 function get_customer_trans_view_str($type, $trans_no, $label="")
74 global $path_to_root, $use_popup_windows;
78 $viewer = "view_invoice.php";
80 $viewer = "view_credit.php";
82 $viewer = "view_receipt.php";
84 $viewer = "view_dispatch.php";
86 $viewer = "view_sales_order.php";
90 if(!is_array($trans_no)) $trans_no = array($trans_no);
94 foreach($trans_no as $trans) {
98 if($preview_str!='') $preview_str .= ',';
102 if ($use_popup_windows)
103 $preview_str .= "<a target='_blank' href='$path_to_root/sales/view/$viewer?trans_no=$trans' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$lbl</a>";
105 $preview_str .= "<a target='_blank' href='$path_to_root/sales/view/$viewer?trans_no=$trans'>$lbl</a>";
108 $preview_str .= $lbl;
114 //--------------------------------------------------------------------------------------
116 function get_banking_trans_view_str($type, $trans_no, $label="")
118 global $path_to_root, $use_popup_windows;
123 $viewer = "bank_transfer_view.php";
125 $viewer = "gl_payment_view.php";
127 $viewer = "gl_deposit_view.php";
138 if ($use_popup_windows)
139 $preview_str = "<a target='_blank' href='$path_to_root/gl/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
141 $preview_str = "<a target='_blank' href='$path_to_root/gl/view/$viewer?trans_no=$trans_no'>$label</a>";
144 $preview_str = $label;
149 //--------------------------------------------------------------------------------------
151 function get_inventory_trans_view_str($type, $trans_no, $label="")
153 global $path_to_root, $use_popup_windows;
157 if ($type == systypes::inventory_adjustment())
158 $viewer = "view_adjustment.php";
159 elseif ($type == systypes::location_transfer())
160 $viewer = "view_transfer.php";
169 if ($use_popup_windows)
170 $preview_str = "<a target='_blank' href='$path_to_root/inventory/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
172 $preview_str = "<a target='_blank' href='$path_to_root/inventory/view/$viewer?trans_no=$trans_no'>$label</a>";
175 $preview_str = $label;
180 //--------------------------------------------------------------------------------------
182 function get_manufacturing_trans_view_str($type, $trans_no, $label="")
184 global $path_to_root, $use_popup_windows;
189 $viewer = "wo_issue_view.php";
191 $viewer = "wo_production_view.php";
192 elseif ($type == systypes::work_order())
193 $viewer = "work_order_view.php";
202 if ($use_popup_windows)
203 $preview_str = "<a target='_blank' href='$path_to_root/manufacturing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
205 $preview_str = "<a target='_blank' href='$path_to_root/manufacturing/view/$viewer?trans_no=$trans_no'>$label</a>";
208 $preview_str = $label;
213 //--------------------------------------------------------------------------------------
215 function get_dimensions_trans_view_str($type, $trans_no, $label="")
217 global $path_to_root, $use_popup_windows;
222 $viewer = "view_dimension.php";
231 if ($use_popup_windows)
232 $preview_str = "<a target='_blank' href='$path_to_root/dimensions/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$label</a>";
234 $preview_str = "<a target='_blank' href='$path_to_root/dimensions/view/$viewer?trans_no=$trans_no'>$label</a>";
237 $preview_str = $label;
242 //--------------------------------------------------------------------------------------
244 function get_trans_view_str($type, $trans_no, $label="")
246 $view_str = get_customer_trans_view_str($type, $trans_no, $label);
247 if ($view_str != null)
250 $view_str = get_supplier_trans_view_str($type, $trans_no, $label);
251 if ($view_str != null)
254 $view_str = get_banking_trans_view_str($type, $trans_no, $label);
255 if ($view_str != null)
258 $view_str = get_inventory_trans_view_str($type, $trans_no, $label);
259 if ($view_str != null)
262 $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label);
263 if ($view_str != null)
266 $view_str = get_dimensions_trans_view_str($type, $trans_no, $label);
267 if ($view_str != null)
273 //--------------------------------------------------------------------------------------
275 function exchange_rate_display($from_currency, $to_currency, $date_, $buttons=true)
277 if ($from_currency != $to_currency)
279 if ($buttons && isset($_POST['get_rate']))
281 $comp_currency = get_company_currency();
282 if ($from_currency == $comp_currency)
283 $currency = $to_currency;
285 $currency = $from_currency;
286 $rate = get_ecb_rate($currency);
287 if (get_date_exchange_rate($currency, $date_))
288 update_exchange_rate($currency, $date_, $rate, $rate);
290 add_exchange_rate($currency, $date_, $rate, $rate);
291 if ($from_currency == $comp_currency)
295 $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
296 $rate = number_format2($rate, user_exrate_dec());
297 label_row(_("Exchange Rate:"),"1 " . $from_currency . " = " . $rate . " " . $to_currency .
298 ($buttons?" " . submit('get_rate',_("Get"), false):""));
302 //--------------------------------------------------------------------------------------
304 function is_voided_display($type, $id, $label)
307 $void_entry = get_voided_entry($type, $id);
309 if ($void_entry == null)
312 start_table("width=50% $table_style");
313 echo "<tr><td align=center><font color=red>$label</font><br>";
314 echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
315 if (strlen($void_entry["memo_"]) > 0)
316 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font><br>";
323 //--------------------------------------------------------------------------------------
325 function comments_display_row($type, $id)
327 $comments = get_comments($type, $id);
328 if ($comments and db_num_rows($comments))
330 echo "<tr><td colspan=15>";
331 while ($comment = db_fetch($comments))
333 echo $comment["memo_"] . "<br>";
339 //--------------------------------------------------------------------------------------
341 function get_comments_string($type, $type_no)
344 $result = get_comments($type, $type_no);
345 while ($comment = db_fetch($result))
347 if (strlen($str_return))
348 $str_return = $str_return . " \n";
349 $str_return = $str_return . $comment["memo_"];
354 //--------------------------------------------------------------------------------------
356 function view_stock_status($stock_id, $description=null)
358 global $path_to_root;
360 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
361 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >". (user_show_codes()?$stock_id . " - ":"") . $description."</a>";
363 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
364 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$stock_id</a>";
368 function view_stock_status_cell($stock_id, $description=null)
371 view_stock_status($stock_id, $description);
375 //--------------------------------------------------------------------------------------
377 function display_debit_or_credit_cells($value)
387 amount_cell(abs($value));
397 //--------------------------------------------------------------------------------------
399 function display_customer_trans_tax_details($tax_items, $columns)
401 while ($tax_item = db_fetch($tax_items))
403 $tax = number_format2($tax_item['amount'],user_price_dec());
404 if ($tax_item['included_in_price'])
405 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
406 _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
408 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
409 $tax, "colspan=$columns align=right", "align=right");
413 //--------------------------------------------------------------------------------------
415 function display_supp_trans_tax_details($tax_items, $columns)
417 while ($tax_item = db_fetch($tax_items))
419 $tax = number_format2(abs($tax_item['amount']),user_price_dec());
420 if ($tax_item['included_in_price'])
421 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
422 _("Amount:") . ": $tax", "colspan=$columns align=right", "align=right");
424 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
425 $tax, "colspan=$columns align=right", "align=right");
429 //--------------------------------------------------------------------------------------
431 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
435 foreach ($taxes as $taxitem)
439 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
440 _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
444 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
445 number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
446 $total += $taxitem['Value'];
453 //--------------------------------------------------------------------------------------
455 function display_footer_exit()
457 global $path_to_root;
463 //--------------------------------------------------------------------------------------
465 function display_allocations($alloc_result, $total)
469 if (!$alloc_result || db_num_rows($alloc_result) == 0)
472 display_heading2(_("Allocations"));
474 start_table("$table_style width=80%");
476 $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
477 _("Left to Allocate"), _("This Allocation"));
479 $k = $total_allocated = 0;
481 while ($alloc_row = db_fetch($alloc_result))
484 alt_table_row_color($k);
486 label_cell(systypes::name($alloc_row['type']));
487 label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
488 label_cell(sql2date($alloc_row['tran_date']));
489 amount_cell($alloc_row['Total']);
490 //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
491 amount_cell($alloc_row['Total'] - $alloc_row['amt']);
492 amount_cell($alloc_row['amt']);
495 $total_allocated += $alloc_row['amt'];
498 label_cell(_("Total Allocated:"), "align=right colspan=5");
499 amount_cell($total_allocated);
502 label_cell(_("Left to Allocate:"), "align=right colspan=5");
503 amount_cell($total - $total_allocated);
509 //--------------------------------------------------------------------------------------
511 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
513 switch ($person_type)
515 case payment_person_types::customer() :
516 $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
517 display_allocations($alloc_result, $total);
519 case payment_person_types::supplier() :
520 $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
521 display_allocations($alloc_result, $total);
526 function get_js_go_back()
528 $js = "\n<script type=\"text/javascript\">\n"
530 . "function goBack()\n"
532 . " if (window.history.length <= 1)\n"
533 . " window.close();\n"
535 . " window.history.go(-1);\n"
542 function get_js_open_window($width, $height)
544 $js = "\n<script type=\"text/javascript\">\n"
546 . "function openWindow(url, title)\n"
548 . " var left = (screen.width - $width) / 2;\n"
549 . " var top = (screen.height - $height) / 2;\n"
550 . " window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
557 //$focus_on = array();
559 Setting focus on element $name in $form.
560 If $form<0 $name is element id.
562 function set_focus($name, $form_no=0) {
564 // $focus_on['name'] = $name;
565 // $focus_on['form'] = $form_no;
566 $_POST['_focus'] = $name;
569 // Set default focus on first field $name if not set yet
571 function default_focus($name, $form_no=0) {
573 // if (!isset($focus_on['name']) && (!isset($_POST['_focus']) || $_POST['_focus']=='') ) {
574 //echo "<h2>$name</h2>";
575 // $focus_on['name'] = $name;
576 // $focus_on['form'] = $form_no;
578 if (!isset($_POST['_focus'])) {
579 $_POST['_focus'] = $name;
583 function set_js_focus() {
587 // if (isset($focus_on['name'])) {
589 $js = "<script type=\"text/javascript\">\n"
590 ."Behaviour.addLoadEvent(function(){ setFocus('".$focus_on['name']."'".( $focus_on['form']>=0 ? (",".$focus_on['form']): '').
597 function get_js_png_fix()
599 $js = "<script type=\"text/javascript\">\n"
600 . "function fixPNG(myImage)\n"
602 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
603 . " var version = parseFloat(arVersion[1])\n"
604 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
606 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
607 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
608 . " var imgTitle = (myImage.title) ?\n"
609 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
610 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
611 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
612 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
613 . " + \"px; height:\" + myImage.height\n"
614 . " + \"px;\" + imgStyle + \";\"\n"
615 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
616 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
617 . " myImage.outerHTML = strNewHTML\n"
624 function get_js_date_picker()
627 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
630 #CCIFrame { display: none; left: 0px; position: absolute; top: 0px; height: 250px; width: 250px; z-index: 99;}
631 #CC { position:absolute; background-color:#FFF; margin:0; padding:0; display:none; z-index: 100;}
632 #CC table { font-family: arial, verdana, helvetica, sans-serif;font-size: 8pt; border-left: 1px solid #336; border-right: 1px solid #336;}
633 #CC th { font-weight: normal;}
634 #CC th a { font-weight: normal; text-decoration: none; color: #FFF; padding: 1px;}
635 #CC td { text-align: center;}
636 #CC .header { background-color: #336;}
637 #CC .weekday { background-color: #DDD; color: #000;}
638 #CC .weekend { background-color: #FFC; color: #000;}
639 #CC .current { border: 1px solid #339; background-color: #336; color: #FFF;}
640 #CC .weekday,#CC .weekend,#CC .current { display: block; text-decoration: none; border: 1px solid #FFF; width: 2em;}
641 #CC .weekday:hover,#CC .weekend:hover,#CC .current:hover { color: #FFF; background-color: #336; border: 1px solid #999;}
642 #CC .previous { text-align: left;}
643 #CC .next { text-align: right;}
644 #CC .previous,#CC .next { padding: 1px 3px 1px 3px; font-size: 1.4em;}
645 #CC .previous a,#CC .next a { color: #FFF; text-decoration: none; font-weight: bold;}
646 #CC .title { text-align: center; font-weight: bold; color: #FFF;}
647 #CC .empty { background-color: #CCC; border: 1px solid #FFF;}
652 if (!file_exists($fpath)) {
654 global $dateseps, $date_system;
656 $how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
657 $sep = $dateseps[user_date_sep()]; // date separator
658 $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
659 $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
660 $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
662 if ($date_system == 1)
663 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
664 else if ($date_system == 2)
665 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
669 function positionInfo(object) {
671 this.getElementLeft = getElementLeft;
672 function getElementLeft() {
675 if(typeof(p_elm) == 'object'){
678 elm = document.getElementById(p_elm);
680 while (elm != null) {
682 elm = elm.offsetParent;
686 this.getElementWidth = getElementWidth;
687 function getElementWidth(){
689 if(typeof(p_elm) == 'object'){
692 elm = document.getElementById(p_elm);
694 return parseInt(elm.offsetWidth);
696 this.getElementRight = getElementRight;
697 function getElementRight(){
698 return getElementLeft(p_elm) + getElementWidth(p_elm);
700 this.getElementTop = getElementTop;
701 function getElementTop() {
704 if(typeof(p_elm) == 'object'){
707 elm = document.getElementById(p_elm);
709 while (elm != null) {
711 elm = elm.offsetParent;
715 this.getElementHeight = getElementHeight;
716 function getElementHeight(){
718 if(typeof(p_elm) == 'object'){
721 elm = document.getElementById(p_elm);
723 return parseInt(elm.offsetHeight);
725 this.getElementBottom = getElementBottom;
726 function getElementBottom(){
727 return getElementTop(p_elm) + getElementHeight(p_elm);
731 var calendarId = 'CC';
733 var currentMonth = 0;
735 var selectedYear = 0;
736 var selectedMonth = 0;
738 var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]'];
739 var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
740 var dateField = null;
741 function getProperty(p_property){
742 var p_elm = calendarId;
744 if(typeof(p_elm) == 'object'){
747 elm = document.getElementById(p_elm);
753 return elm[p_property];
762 function setElementProperty(p_property, p_value, p_elmId){
765 if(typeof(p_elm) == 'object'){
768 elm = document.getElementById(p_elm);
770 if((elm != null) && (elm.style != null)){
772 elm[ p_property ] = p_value;
775 function setProperty(p_property, p_value) {
776 setElementProperty(p_property, p_value, calendarId);
778 function getDaysInMonth(year, month) {
780 if ($date_system == 1)
782 return [31,31,31,31,31,31,30,30,30,30,30,(((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682 ? 30 : 29)][month-1];
784 else if ($date_system == 2)
786 return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
790 return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
794 function getDayOfWeek(year, month, day) {
796 if ($date_system == 1 || $date_system == 2)
801 return a - (b * Math.floor(a / b));
805 return mod(Math.floor((j + 1.5)), 7);
808 if ($date_system == 1)
810 var epbase, epyear, t;
811 epbase = year - ((year >= 0) ? 474 : 473);
812 epyear = 474 + mod(epbase, 2820);
813 t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
814 Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
815 Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
817 else if ($date_system == 2)
820 t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
821 Math.floor((month - 1) / 2) + day + 1948440 - 385;
829 var date = new Date(year,month-1,day)
830 return date.getDay();
834 this.clearDate = clearDate;
835 function clearDate() {
836 dateField.value = '';
839 this.setDate = setDate;
840 function setDate(year, month, day) {
842 if (month < 10) {month = '0' + month;}
843 if (day < 10) {day = '0' + day;}
847 var dateString = month+'$sep'+day+'$sep'+year;
851 var dateString = day+'$sep'+month+'$sep'+year;
855 var dateString = year+'$sep'+month+'$sep'+day;
858 dateField.value = dateString;
863 this.changeMonth = changeMonth;
864 function changeMonth(change) {
865 currentMonth += change;
867 if(currentMonth > 12) {
870 } else if(currentMonth < 1) {
874 calendar = document.getElementById(calendarId);
875 calendar.innerHTML = calendarDrawTable();
877 this.changeYear = changeYear;
878 function changeYear(change) {
879 currentYear += change;
881 calendar = document.getElementById(calendarId);
882 calendar.innerHTML = calendarDrawTable();
884 function getCurrentYear() {
885 var year = new Date().getYear();
886 if(year < 1900) year += 1900;
889 function getCurrentMonth() {
890 return new Date().getMonth() + 1;
892 function getCurrentDay() {
893 return new Date().getDate();
895 function calendarDrawTable() {
897 var wstart = $wstart;
899 var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
900 var daysInMonth = getDaysInMonth(currentYear, currentMonth);
901 var css_class = null; //CSS class for each day
902 var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
903 table += \"<tr class='header'>\";
904 table += \" <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'><</a><br><a href='javascript:changeCCYear(-1);'>«</a></td>\";
905 table += \" <td colspan='3' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
906 table += \" <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>></a><br><a href='javascript:changeCCYear(1);'>»</a></td>\";
909 for (var n=0; n<7; n++)
910 table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
912 for(var week=0; week < 6; week++) {
914 for(var n=0; n < 7; n++) {
915 dayOfWeek = (wstart+n)%7;
916 if(week == 0 && startDayOfWeek == dayOfWeek) {
918 } else if (validDay == 1 && dayOfMonth > daysInMonth) {
922 if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
923 css_class = 'current';
925 if ($date_system == 1 || $date_system == 2)
927 } else if (dayOfWeek == 5) {
931 } else if (dayOfWeek == 0 || dayOfWeek == 6) {
934 css_class = 'weekend';
936 css_class = 'weekday';
938 table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
941 table += \"<td class='empty'> </td>\";
946 table += \"<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
947 table += \"</table>\";
951 function show(field) {
953 if (dateField == field) {
960 var dateString = new String(dateField.value);
961 var dateParts = dateString.split('$sep');
965 selectedMonth = parseInt(dateParts[0],10);
966 selectedDay = parseInt(dateParts[1],10);
967 selectedYear = parseInt(dateParts[2],10);
971 selectedDay = parseInt(dateParts[0],10);
972 selectedMonth = parseInt(dateParts[1],10);
973 selectedYear = parseInt(dateParts[2],10);
977 selectedYear = parseInt(dateParts[0],10);
978 selectedMonth = parseInt(dateParts[1],10);
979 selectedDay = parseInt(dateParts[2],10);
984 if (!(selectedYear && selectedMonth && selectedDay)) {
986 if ($date_system == 1 || $date_system == 2)
989 selectedMonth = $cmon;
991 selectedYear = $cyear;
997 selectedMonth = getCurrentMonth();
998 selectedDay = getCurrentDay();
999 selectedYear = getCurrentYear();
1004 currentMonth = selectedMonth;
1005 currentDay = selectedDay;
1006 currentYear = selectedYear;
1007 if(document.getElementById){
1008 calendar = document.getElementById(calendarId);
1009 calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1010 setProperty('display', 'block');
1011 var fieldPos = new positionInfo(dateField);
1012 var calendarPos = new positionInfo(calendarId);
1013 var x = fieldPos.getElementLeft();
1014 var y = fieldPos.getElementBottom();
1015 setProperty('left', x + 'px');
1016 setProperty('top', y + 'px');
1018 setElementProperty('display', 'block', 'CCIframe');
1019 setElementProperty('left', x + 'px', 'CCIframe');
1020 setElementProperty('top', y + 'px', 'CCIframe');
1021 setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1022 setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1029 setProperty('display', 'none');
1030 setElementProperty('display', 'none', 'CCIframe');
1034 this.visible = visible;
1035 function visible() {
1038 this.can_hide = can_hide;
1042 function date_picker(textField) {
1050 function setCCDate(year, month, day) {
1051 cC.setDate(year, month, day);
1053 function changeCCYear(change) {
1054 cC.changeYear(change);
1056 function changeCCMonth(change) {
1057 cC.changeMonth(change);
1059 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1060 document.write(\"<div id='CC'></div>\");";
1062 cache_js_file($fpath, $js);
1064 add_js_ufile($fpath);
1070 // Javascript conversions to/from user numeric format.
1072 function add_js_user_num() {
1075 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'user_num.js';
1077 if (!file_exists($fpath)) {
1079 global $thoseps, $decseps;
1080 $ts = $thoseps[user_tho_sep()];
1081 $ds = $decseps[user_dec_sep()];
1083 $js = "function price_format(post, num, dec, label) {
1084 //num = num.toString().replace(/\\$|\\,/g,'');
1087 sign = (num == (num = Math.abs(num)));
1089 decsize = Math.pow(10, dec);
1090 num = Math.floor(num*decsize+0.50000000001);
1091 cents = num%decsize;
1092 num = Math.floor(num/decsize).toString();
1093 for( i=cents.toString().length; i<dec; i++){
1094 cents = \"0\" + cents;
1096 for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
1097 num = num.substring(0,num.length-(4*i+3))+'".$ts."'+
1098 num.substring(num.length-(4*i+3));
1099 num = ((sign)?'':'-') + num;
1100 if(dec!=0) num = num + '".$ds."' + cents;
1102 document.getElementById(post).innerHTML = num;
1104 document.getElementsByName(post)[0].value = num;
1106 function get_amount(doc, label) {
1108 var val = document.getElementById(doc).innerHTML;
1110 var val = document.getElementsByName(doc)[0].value;
1111 val = val.replace(/\\".$ts."/g,'');
1112 val = val.replace(/\\".$ds."/g,'.');
1117 cache_js_file($fpath, $js);
1119 add_js_ufile($fpath);
1122 function add_js_allocate() {
1124 $fpath = $comp_path.'/'.user_company().'/js_cache/'.'allocate.js';
1126 if (!file_exists($fpath)) {
1129 "function allocate_all(doc) {
1130 var amount = get_amount('amount'+doc);
1131 var unallocated = get_amount('un_allocated'+doc);
1132 var total = get_amount('total_allocated', 1);
1133 var left = get_amount('left_to_allocate', 1);
1135 if(unallocated<amount) amount = unallocated;
1136 if((unallocated-amount)<=left){
1137 left-=unallocated-amount;
1138 total+=unallocated-amount;
1145 price_format('amount'+doc, amount, ".user_price_dec().");
1146 price_format('left_to_allocate', left, ".user_price_dec().", 1);
1147 price_format('total_allocated', total, ".user_price_dec().", 1);
1149 function allocate_none(doc) {
1150 amount = get_amount('amount'+doc);
1151 left = get_amount('left_to_allocate', 1);
1152 total = get_amount('total_allocated', 1);
1153 price_format('left_to_allocate',amount+left, ".user_price_dec().", 1);
1154 price_format('amount'+doc, 0, ".user_price_dec().");
1155 price_format('total_allocated', total-amount, ".user_price_dec().", 1);
1158 cache_js_file($fpath, $js);
1160 add_js_ufile($fpath);
1164 function alert($msg)
1166 echo "\n<script type=\"text/javascript\">\n"
1168 . "alert('$msg');\n"
1173 if (!function_exists('_vd'))
1175 function _vd($mixed, $title = '', $exit = false)
1177 // Only the site admin is able to proceed here.
1178 echo (!empty($title) ? ($title .':') : '') .'<pre>';