Exemplo n.º 1
0
/**
 *	return Piece from Pieces Return
 * 
 *	$.ajax({ method:'return', table:'Pieces', barcode:9...9, ...};
 *
 * @return	string	''
 */
function JKY_return_piece($the_data)
{
    $db = Zend_Registry::get('db');
    $my_barcode = get_data($the_data, 'barcode');
    $my_inspected_by = get_data($the_data, 'inspected_by');
    $my_weighed_by = get_data($the_data, 'weighed_by');
    $my_remarks = get_data($the_data, 'remarks');
    $my_checkin_weight = get_data($the_data, 'checkin_weight');
    $my_checkin_location = get_data($the_data, 'checkin_location');
    $sql = 'UPDATE Pieces' . '   SET ' . get_updated() . ',           status="Check In"' . ',     inspected_by=  ' . $my_inspected_by . ',       weighed_by=  ' . $my_weighed_by . ',          remarks=\'' . $my_remarks . '\'' . ',   checkin_weight=  ' . $my_checkin_weight . ', checkin_location=\'' . $my_checkin_location . '\'' . ',       checkin_at=\'' . get_time() . '\'' . ' WHERE id =' . $my_barcode;
    log_sql('Pieces', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Pieces', $my_barcode);
    $my_order_id = get_table_value('Pieces', 'order_id', $my_barcode);
    $my_set = ', produced_at=\'' . get_time() . '\'' . ', produced_pieces = produced_pieces + 1';
    if ($my_remarks != 'boa') {
        $my_set = ', rejected_pieces = rejected_pieces + 1';
    }
    $my_field_name = $my_remarks == 'boa' ? 'produced_pieces' : 'rejected_pieces';
    $sql = 'UPDATE Orders' . '   SET ' . get_updated() . $my_set . ' WHERE id = ' . $my_order_id;
    log_sql('Orders', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Orders', $my_order_id);
    return '';
}
Exemplo n.º 2
0
/**
 *	combine BatchOuts from Threads
 *
 * @param	int		order_id
 * @return	int		count of CheckOuts combined
 */
function JKY_combine_batchouts($the_ids)
{
    $db = Zend_Registry::get('db');
    $my_id = get_next_id('BatchOuts');
    $sql = 'INSERT INTO BatchOuts ' . 'SELECT ' . $my_id . '    	, ' . get_session('user_id') . '     , NOW()' . '     , status' . '     , MIN(checkout_id)' . '     , thread_id' . '     , batchin_id' . '     , req_line_id' . '     , tdyer_thread_id' . '     , order_thread_id' . '     , code' . '     , batch' . '     , AVG(unit_price)' . '     , SUM(requested_weight)' . '     , AVG(average_weight)' . '     , SUM(requested_boxes)' . '     , SUM(reserved_boxes)' . '     , SUM(checkout_boxes)' . '     , SUM(checkout_weight)' . '  FROM BatchOuts' . ' WHERE id IN (' . $the_ids . ')';
    log_sql('BatchOuts', $my_id, $sql);
    $db->query($sql);
    insert_changes($db, 'BatchOuts', $my_id);
    $sql = 'SELECT *' . '  FROM BatchOuts' . ' WHERE id IN (' . $the_ids . ')';
    log_sql('BatchOuts', $my_id, $sql);
    /*
    	$sql= 'UPDATE BatchOuts '
    	    . '   SET status = "History"'
    		. '  FROM BatchOuts'
    		. ' WHERE id IN (' . $the_ids . ')'
    		;
    */
    $my_rows = $db->fetchAll($sql);
    foreach ($my_rows as $my_row) {
        $sql = 'UPDATE BatchOuts' . '   SET status = "History"' . ' WHERE id = ' . $my_row['id'];
        log_sql('BatchOuts', $my_row['id'], $sql);
        $db->query($sql);
        insert_changes($db, 'BatchOuts', $my_row['id']);
    }
    return $my_id;
}
Exemplo n.º 3
0
/**
 *	generate Purchase
 *
 * @param	int		purchase_id
 * @return	int		count of Incomings generated
 */
function JKY_generate_purchase($the_id)
{
    $db = Zend_Registry::get('db');
    $sql = 'SELECT *' . '  FROM Purchases' . ' WHERE id = ' . $the_id;
    $my_purchase = $db->fetchRow($sql);
    $sql = 'SELECT *' . '  FROM PurchaseLines' . ' WHERE parent_id = ' . $the_id;
    $my_rows = $db->fetchAll($sql);
    $my_count = 0;
    foreach ($my_rows as $my_row) {
        $my_incoming_id = get_next_id('Incomings');
        $sql = 'INSERT Incomings' . '   SET         id = ' . $my_incoming_id . ',      updated_by = ' . get_session('user_id') . ',      updated_at ="' . get_time() . '"' . ', incoming_number = ' . $my_incoming_id . ',     supplier_id = ' . $my_purchase['supplier_id'] . ',    invoice_date ="' . $my_row['expected_date'] . '"' . ',  invoice_weight = ' . $my_row['expected_weight'];
        log_sql('Incomings', 'INSERT', $sql);
        $db->query($sql);
        insert_changes($db, 'Incomings', $my_incoming_id);
        $my_batchin_id = get_next_id('Batches');
        $sql = 'INSERT Batches' . '   SET          id = ' . $my_batchin_id . ',       updated_by = ' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',      incoming_id = ' . $my_incoming_id . ',        thread_id = ' . $my_row['thread_id'] . ', purchase_line_id = ' . $my_row['id'];
        log_sql('Batches', 'INSERT', $sql);
        $db->query($sql);
        insert_changes($db, 'Batches', $my_batchin_id);
        $sql = 'UPDATE PurchaseLines' . '   SET batch_id =  ' . $my_batchin_id . ' WHERE id = ' . $my_row['id'];
        log_sql('PurchaseLines', 'UPDATE', $sql);
        $db->query($sql);
        insert_changes($db, 'PurchaseLines', $my_row['id']);
        $my_count++;
    }
    $sql = 'UPDATE Purchases' . '   SET status = "Active"' . ' WHERE id = ' . $the_id;
    log_sql('Purchases', 'UPDATE', $sql);
    $db->query($sql);
    insert_changes($db, 'Purchases', $the_id);
    return $my_count;
}
Exemplo n.º 4
0
/**
 *	generate Order from OSAs
 *
 * @param	int		quotation_id
 * @return	int		count of Orders generated
 */
function JKY_generate_order($the_id)
{
    $db = Zend_Registry::get('db');
    $sql = 'SELECT *' . '  FROM OSAs' . ' WHERE id = ' . $the_id;
    $my_osa = $db->fetchRow($sql);
    $sql = 'SELECT *' . '  FROM OSA_Lines' . ' WHERE parent_id = ' . $the_id;
    $my_rows = $db->fetchAll($sql);
    $my_count = 0;
    foreach ($my_rows as $my_row) {
        $my_osa_line_id = $my_row['id'];
        $sql = 'SELECT *' . '  FROM OSA_Colors' . ' WHERE parent_id = ' . $my_osa_line_id;
        $my_colors = $db->fetchAll($sql);
        foreach ($my_colors as $my_color) {
            $my_order_id = get_next_id('Orders');
            $sql = 'INSERT Orders' . '   SET          id =' . $my_order_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',     order_number =' . $my_order_id . ',      osa_line_id =' . $my_osa_line_id . ',       osa_number =' . $my_osa['osa_number'] . ',       ordered_at ="' . $my_osa['ordered_at'] . '"' . ',        needed_at ="' . $my_osa['needed_at'] . '"' . ',     quoted_units =' . $my_row['units'] . ',    quoted_pieces =' . $my_color['quoted_pieces'] . ',    quoted_weight =' . $my_color['quoted_weight'] . ',   ordered_pieces =' . $my_color['ordered_pieces'] . ',   ordered_weight =' . $my_color['ordered_weight'];
            if ($my_osa['customer_id']) {
                $sql .= ', customer_id=' . $my_osa['customer_id'];
            }
            if ($my_row['product_id']) {
                $sql .= ',  product_id=' . $my_row['product_id'];
            }
            if ($my_color['color_id']) {
                $sql .= ',    color_id=' . $my_color['color_id'];
            }
            if ($my_color['ftp_id']) {
                $sql .= ',      ftp_id=' . $my_color['ftp_id'];
            }
            if ($my_color['machine_id']) {
                $sql .= ',  machine_id=' . $my_color['machine_id'];
            }
            if ($my_color['partner_id']) {
                $sql .= ',  partner_id=' . $my_color['partner_id'];
            }
            log_sql('Orders', 'INSERT', $sql);
            $db->query($sql);
            insert_changes($db, 'Orders', $my_order_id);
            /*
            			$sql= 'UPDATE OSA_lines'
            				. '   SET status = "Active"'
            				. ' WHERE id = ' . $my_row['id']
            				;
            	log_sql('OSA_Lines', 'UPDATE', $sql);
            			$db->query($sql);
            			insert_changes($db, 'OSA_Lines', $my_row['id']);
            */
            $my_count++;
        }
    }
    $sql = 'UPDATE OSAs' . '   SET status = "Active"' . ' WHERE id = ' . $the_id;
    log_sql('OSAs', 'UPDATE', $sql);
    $db->query($sql);
    insert_changes($db, 'OSAs', $the_id);
    return $my_count;
}
Exemplo n.º 5
0
/**
 *	generate CheckOut from Planning Orders
 *
 * @param	int		order_id
 * @return	int		count of CheckOuts generated
 */
function JKY_generate_checkout($the_id)
{
    $db = Zend_Registry::get('db');
    $sql = 'SELECT *' . '  FROM Orders' . ' WHERE id = ' . $the_id;
    $my_order = $db->fetchRow($sql);
    $sql = 'SELECT *' . '  FROM OrdThreads' . ' WHERE parent_id = ' . $the_id;
    $my_rows = $db->fetchAll($sql);
    /*
    	$my_needed_at = $my_order['needed_at'];
    	if ($my_needed_at == null) {
    		$my_needed_at = get_time();
    	}
    */
    $my_checkout_id = get_next_id('CheckOuts');
    $sql = 'INSERT CheckOuts' . '   SET          id =' . $my_checkout_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',           number =' . $my_checkout_id . ',     requested_at ="' . get_time() . '"' . ', requested_weight =' . $my_order['ordered_weight'];
    if ($my_order['machine_id']) {
        $sql .= ', machine_id=' . $my_order['machine_id'];
    }
    if ($my_order['partner_id']) {
        $sql .= ', partner_id=' . $my_order['partner_id'];
    }
    log_sql('CheckOuts', 'INSERT', $sql);
    $db->query($sql);
    insert_changes($db, 'CheckOuts', $my_checkout_id);
    $my_count = 0;
    foreach ($my_rows as $my_row) {
        $my_ord_thread_id = $my_row['id'];
        $my_batch = db_get_row('Batches', 'id=' . $my_row['batchin_id']);
        $my_ordered_weight = $my_row['ordered_weight'];
        $my_ordered_boxes = ceil((double) $my_ordered_weight / (double) $my_batch['average_weight']);
        $my_batchout_id = get_next_id('BatchOuts');
        $sql = 'INSERT BatchOuts' . '   SET          id =' . $my_batchout_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',      checkout_id =' . $my_checkout_id . ',        thread_id =' . $my_row['thread_id'] . ',       batchin_id =' . $my_row['batchin_id'] . ',  order_thread_id =' . $my_ord_thread_id . ',            batch ="' . $my_batch['batch'] . '"' . ',       unit_price =' . $my_batch['unit_price'] . ',   average_weight =' . $my_batch['average_weight'] . ', requested_weight =' . $my_ordered_weight . ',  requested_boxes =' . $my_ordered_boxes;
        log_sql('BatchOuts', 'INSERT', $sql);
        $db->query($sql);
        insert_changes($db, 'BatchOuts', $my_batchout_id);
        $sql = 'UPDATE OrdThreads' . '   SET batchout_id = ' . $my_batchout_id . ' WHERE id = ' . $my_ord_thread_id;
        log_sql('OrdThreads', 'UPDATE', $sql);
        $db->query($sql);
        insert_changes($db, 'OrdThreads', $my_ord_thread_id);
        $my_count++;
    }
    $sql = 'UPDATE Orders' . '   SET status = "Active"' . ' WHERE id = ' . $the_id;
    log_sql('Orders', 'UPDATE', $sql);
    $db->query($sql);
    insert_changes($db, 'Orders', $the_id);
    return $my_count;
}
Exemplo n.º 6
0
/**
 *	checkin Piece from Pieces Check In
 *
 *	$.ajax({ method:'checkin', table:'Pieces', barcode:9...9, ...};
 *
 * @return	string	''
 */
function JKY_checkin_piece($the_data)
{
    $db = Zend_Registry::get('db');
    $my_barcode = get_data($the_data, 'barcode');
    $my_checkin_weight = get_data($the_data, 'checkin_weight');
    /*
    	$my_inspected_by	= get_data($the_data, 'inspected_by'	);
    	$my_weighed_by		= get_data($the_data, 'weighed_by'		);
    	$my_qualities		= get_data($the_data, 'qualities'		);
    	$my_remarks			= get_data($the_data, 'remarks'			);
    	$my_checkin_weight	= get_data($the_data, 'checkin_weight'	);
    	$my_checkin_location= get_data($the_data, 'checkin_location');
    */
    $my_set = '';
    //	$my_set .= isset($the_data['revised_by'			]) ?       ', revised_by = '  . trim($the_data['revised_by'			])			: '';
    $my_set .= ', revised_by = ' . get_session('user_id');
    //	$my_set .= isset($the_data['weighed_by'			]) ?       ', weighed_by = '  . trim($the_data['weighed_by'			])			: '';
    $my_set .= ', weighed_by = ' . get_session('user_id');
    $my_set .= isset($the_data['qualities']) ? ', qualities =\'' . trim($the_data['qualities']) . '\'' : '';
    $my_set .= isset($the_data['remarks']) ? ', remarks =\'' . trim($the_data['remarks']) . '\'' : '';
    $my_set .= isset($the_data['checkin_weight']) ? ', checkin_weight = ' . trim($the_data['checkin_weight']) : '';
    $my_set .= isset($the_data['checkin_location']) ? ', checkin_location =\'' . trim($the_data['checkin_location']) . '\'' : '';
    $sql = 'UPDATE Pieces' . '   SET ' . get_updated() . ',       checkin_at=\'' . get_time() . '\'' . $my_set . ' WHERE id =' . $my_barcode;
    log_sql('Pieces', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Pieces', $my_barcode);
    $my_piece = db_get_row('Pieces', 'barcode =\'' . $my_barcode . '\'');
    if (!is_empty($my_piece['revised_by']) && !is_empty($my_piece['weighed_by'])) {
        $sql = 'UPDATE Pieces' . '   SET status="Check In"' . ' WHERE id = ' . $my_barcode;
        log_sql('Pieces', 'update', $sql);
        $db->query($sql);
    }
    //	$my_order_id = get_table_value('Pieces', 'order_id', $my_barcode);
    $my_order_id = $my_piece['order_id'];
    if (strtolower($my_piece['qualities']) == 'boa') {
        $my_set = ', produced_at=\'' . get_time() . '\'' . ', produced_pieces = produced_pieces + 1' . ', produced_weight = produced_weight + ' . $my_checkin_weight;
    } else {
        $my_set = ', rejected_pieces = rejected_pieces + 1';
    }
    $sql = 'UPDATE Orders' . '   SET ' . get_updated() . $my_set . ' WHERE id = ' . $my_order_id;
    log_sql('Orders', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Orders', $my_order_id);
    return '';
}
Exemplo n.º 7
0
 private function history_log($method, $table, $parent_id, $new, $old)
 {
     $history = '';
     $first = '';
     foreach ($new as $key => $value) {
         if ($method == 'update') {
             if ($key != 'updated_at' and $new[$key] != $old[$key]) {
                 $history .= $first . $key . ':' . $old[$key] . '=>' . $value;
                 $first = ', ';
             }
         } else {
             $history .= $first . $key . ':' . $value;
             $first = ', ';
         }
     }
     if (empty($history)) {
         return;
     }
     $my_id = get_next_id('History');
     $sql = 'INSERT History' . '   SET     id=' . $my_id . ',  updated_by=' . get_session('user_id') . ',  updated_at="' . get_time() . '"' . ', parent_name="' . $table . '"' . ',   parent_id=' . $parent_id . ',      method="' . $method . '"' . ',     history="' . $history . '"';
     //$this->log_sql('History', $my_id, $sql);
     $db = Zend_Registry::get('db');
     $db->query($sql);
     insert_changes($db, 'History', $my_id);
 }
Exemplo n.º 8
0
/**
 *	invoice to Dyer from ShipDyer
 *
 * @param	int		shipdyer_id
 * @return	int		count of Records generated
 */
function JKY_invoice_dyer($the_id)
{
    $domain = get_config_value('NFe Dyer', 'domain');
    $my_return = json_decode(proxy($domain, 'data={"method":"check_status"}'), true);
    if (!isset($my_return['status'])) {
        JKY_echo_error('domain [' . $domain . '] is not active');
        return;
    }
    if ($my_return['status'] != 'ok') {
        JKY_echo_error($my_return['message']);
        return;
    }
    $db = Zend_Registry::get('db');
    $ship_dyer = db_get_row('ShipDyers', 'id=' . $the_id);
    $dyer = db_get_row('Contacts', 'id=' . $ship_dyer['dyer_id']);
    $company['pessoa'] = $dyer['is_company'] == 'Yes' ? 'J' : 'F';
    $company['name'] = $dyer['full_name'];
    $company['fantasia'] = $dyer['nick_name'];
    $company['email'] = $dyer['email'];
    $company['phone'] = $dyer['phone'];
    $company['fax'] = $dyer['fax'];
    $company['cnpj'] = $dyer['cnpj'];
    $company['ie'] = $dyer['ie'];
    $company['district'] = $dyer['district'];
    $company['number'] = $dyer['st_number'];
    $company['cpl'] = $dyer['st_cpl'];
    $company['street1'] = $dyer['street1'];
    $company['street2'] = $dyer['street2'];
    $company['zip'] = $dyer['zip'];
    $company['city'] = $dyer['city'];
    $company['state'] = $dyer['state'];
    $company['country'] = $dyer['country'];
    $my_return = json_decode(proxy($domain, 'data={"method":"add_company", "row":' . json_encode($company) . '}'), true);
    $my_id = $my_return['id'];
    log_sql('Dyer', 'INSERT', $my_id);
    $transport = db_get_row('Contacts', 'id=' . $ship_dyer['transport_id']);
    $company['pessoa'] = $transport['is_company'] == 'Yes' ? 'J' : 'F';
    $company['name'] = $transport['full_name'];
    $company['fantasia'] = $transport['nick_name'];
    $company['email'] = $transport['email'];
    $company['phone'] = $transport['phone'];
    $company['fax'] = $transport['fax'];
    $company['cnpj'] = $transport['cnpj'];
    $company['ie'] = $transport['ie'];
    $company['district'] = $transport['district'];
    $company['number'] = $transport['st_number'];
    $company['cpl'] = $transport['st_cpl'];
    $company['street1'] = $transport['street1'];
    $company['street2'] = $transport['street2'];
    $company['zip'] = $transport['zip'];
    $company['city'] = $transport['city'];
    $company['state'] = $transport['state'];
    $company['country'] = $transport['country'];
    $my_return = json_decode(proxy($domain, 'data={"method":"add_company", "row":' . json_encode($company) . '}'), true);
    $my_id = $my_return['id'];
    log_sql('Transport', 'INSERT', $my_id);
    $i = 0;
    $total_volume = 0;
    $items = array();
    $loadouts = db_get_rows('LoadOuts', 'shipdyer_id=' . $the_id);
    foreach ($loadouts as $loadout) {
        $loadquots = db_get_rows('LoadQuotations', 'loadout_id=' . $loadout['id']);
        foreach ($loadquots as $loadquot) {
            $pieces = db_get_rows('Pieces', 'load_quot_id=' . $loadquot['id']);
            $order = db_get_row('Orders', 'id=' . $pieces[0]['order_id']);
            $ftp = db_get_row('FTPs', 'id=' . $order['ftp_id']);
            $prod = db_get_row('Products', 'id=' . $order['product_id']);
            $total_weight = 0;
            foreach ($pieces as $piece) {
                $total_volume++;
                $total_weight += $piece['checkin_weight'];
            }
            $item['NFe_id'] = 'null';
            $item['cProd'] = get_config_value('NFe Dyer', 'cProd');
            $item['xProd'] = $prod['product_name'];
            $item['cor_code'] = get_config_value('NFe Dyer', 'cor_code');
            $item['cor_type'] = get_config_value('NFe Dyer', 'cor_type');
            $item['composicao'] = $ftp['composition'];
            $item['NCM'] = get_config_value('NFe Dyer', 'NCM');
            $item['CFOP'] = get_config_value('NFe Dyer', 'CFOP');
            $item['uCom'] = get_config_value('NFe Dyer', 'uCom');
            $item['qCom'] = $total_weight;
            $item['vUnCom'] = get_config_value('NFe Dyer', 'vUnCom');
            $item['orig'] = get_config_value('NFe Dyer', 'orig');
            $item['CST_ICMS'] = get_config_value('NFe Dyer', 'CST_ICMS');
            $item['CST_IPI'] = get_config_value('NFe Dyer', 'CST_IPI');
            $item['pIPI'] = get_config_value('NFe Dyer', 'pIPI');
            $item['pPIS'] = get_config_value('NFe Dyer', 'pPIS');
            $item['pCOFINS'] = get_config_value('NFe Dyer', 'pCOFINS');
            $items[$i] = $item;
            $i++;
            $product['product_code'] = get_config_value('NFe Dyer', 'cProd');
            $product['product_cf'] = get_config_value('NFe Dyer', 'NCM');
            $product['IPI_code'] = get_config_value('NFe Dyer', 'CST_IPI');
            $product['IPI_aliquota'] = get_config_value('NFe Dyer', 'pIPI');
            $product['product_title'] = $prod['product_name'];
            $product['composicao'] = $ftp['composition'];
            $my_return = json_decode(proxy($domain, 'data={"method":"add_product", "row":' . json_encode($product) . '}'), true);
            $my_id = $my_return['id'];
            log_sql('Product', 'INSERT', $my_id);
        }
    }
    $my_count = 0;
    $nfe['dEmi'] = get_date();
    $nfe['dSaiEnt'] = get_date();
    $nfe['tpNF'] = get_config_value('NFe Dyer', 'tpNF');
    $nfe['natOp'] = get_config_value('NFe Dyer', 'natOp');
    $nfe['dxNome'] = $dyer['full_name'];
    $nfe['txNome'] = $transport['full_name'];
    $nfe['modFrete'] = get_config_value('NFe Dyer', 'modFrete');
    $nfe['qVol'] = $total_volume;
    $nfe['esp'] = get_config_value('NFe Dyer', 'esp');
    $nfe['marca'] = get_config_value('NFe Dyer', 'marca');
    $nfe['pesoL'] = '0';
    $nfe['infCpl'] = get_config_value('NFe Dyer', 'infCpl');
    log_sql('NFe', 'BEFORE INSERT', json_encode($nfe));
    $my_return = json_decode(proxy($domain, 'data={"method":"add_nfe", "row":' . json_encode($nfe) . '}'), true);
    $my_nfe_id = $my_return['id'];
    if ($my_nfe_id) {
        $my_count++;
    }
    log_sql('NFe', 'INSERT', $my_nfe_id);
    foreach ($items as $item) {
        $item['NFe_id'] = $my_nfe_id;
        $my_return = json_decode(proxy($domain, 'data={"method":"add_nfeitem", "row":' . json_encode($item) . '}'), true);
        $my_id = $my_return['id'];
        if ($my_id) {
            $my_count++;
        }
        log_sql('NFeItem', 'INSERT', $my_id);
    }
    $sql = 'UPDATE ShipDyers' . '   SET status = "Active"' . ' WHERE id = ' . $the_id;
    log_sql('ShipDyers', 'UPDATE', $sql);
    $db->query($sql);
    insert_changes($db, 'ShipDyers', $the_id);
    JKY_echo_count($my_count);
}
Exemplo n.º 9
0
/**
 *	generate OSA from Quotations
 *
 * @param	int		quotation_id
 * @return	int		count of OSA Lines generated
 */
function JKY_generate_osa($the_id)
{
    $db = Zend_Registry::get('db');
    $sql = 'SELECT *' . '  FROM Quotations' . ' WHERE id = ' . $the_id;
    $my_quotation = $db->fetchRow($sql);
    $my_needed_at = $my_quotation['needed_at'];
    if ($my_needed_at == null) {
        $my_needed_at = get_time();
    }
    $my_osa_id = get_next_id('OSAs');
    $sql = 'INSERT OSAs' . '   SET          id =' . $my_osa_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',       osa_number =' . $my_osa_id . ',     quotation_id =' . $the_id . ',       ordered_at ="' . get_time() . '"' . ',        needed_at ="' . $my_needed_at . '"' . ',    quoted_pieces =' . $my_quotation['quoted_pieces'] . ',   ordered_pieces =' . $my_quotation['quoted_pieces'] . ',          remarks ="' . $my_quotation['remarks'] . '"';
    if ($my_quotation['customer_id']) {
        $sql .= ',      customer_id=' . $my_quotation['customer_id'];
    }
    if ($my_quotation['salesman_id']) {
        $sql .= ',      salesman_id=' . $my_quotation['salesman_id'];
    }
    log_sql('OSAs', 'INSERT', $sql);
    $db->query($sql);
    insert_changes($db, 'OSAs', $my_osa_id);
    $sql = 'SELECT *' . '  FROM QuotLines' . ' WHERE parent_id = ' . $the_id;
    $my_rows = $db->fetchAll($sql);
    $my_count = 0;
    foreach ($my_rows as $my_row) {
        $my_osa_line_id = get_next_id('OSA_Lines');
        $sql = 'INSERT OSA_Lines' . '   SET          id =' . $my_osa_line_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',        parent_id =' . $my_osa_id . ',             peso =' . $my_row['peso'] . ',     quoted_units =' . $my_row['quoted_units'] . ',            units =' . $my_row['units'] . ',    quoted_pieces =' . $my_row['quoted_pieces'] . ',   ordered_pieces =' . $my_row['quoted_pieces'] . ',    quoted_weight =' . $my_row['quoted_weight'] . ',   ordered_weight =' . $my_row['quoted_weight'] . ',		  remarks ="' . $my_row['remarks'] . '"';
        if ($my_row['product_id']) {
            $sql .= ',       product_id=' . $my_row['product_id'];
        }
        log_sql('OSA_Lines', 'INSERT', $sql);
        $db->query($sql);
        insert_changes($db, 'OSA_Lines', $my_osa_line_id);
        $sql = 'SELECT *' . '  FROM QuotColors' . ' WHERE parent_id = ' . $my_row['id'];
        $my_colors = $db->fetchAll($sql);
        foreach ($my_colors as $my_color) {
            $my_osa_color_id = get_next_id('OSA_Colors');
            if ($my_row['units'] == 0) {
                $my_quoted_pieces = ceil($my_color['quoted_units'] / $my_row['peso']);
                $my_quoted_weight = $my_color['quoted_units'];
            } else {
                $my_quoted_pieces = ceil($my_color['quoted_units'] / $my_row['units']);
                $my_quoted_weight = $my_color['quoted_units'] * $my_row['peso'];
            }
            $sql = 'INSERT OSA_Colors' . '   SET          id =' . $my_osa_color_id . ',       updated_by =' . get_session('user_id') . ',       updated_at ="' . get_time() . '"' . ',        parent_id =' . $my_osa_line_id . ',    quoted_pieces =' . $my_quoted_pieces . ',    quoted_weight =' . $my_quoted_weight . ',   ordered_pieces =' . $my_quoted_pieces . ',   ordered_weight =' . $my_quoted_weight;
            //			if ($my_quotation['customer_id'])	$sql .= ',      customer_id='  . $my_quotation['customer_id'];
            if ($my_row['machine_id']) {
                $sql .= ',       machine_id=' . $my_row['machine_id'];
            }
            //			if ($my_row['product_id'])			$sql .= ',       product_id='  . $my_row['product_id'];
            if ($my_color['color_id']) {
                $sql .= ',         color_id=' . $my_color['color_id'];
            }
            log_sql('OSA_Colors', 'INSERT', $sql);
            $db->query($sql);
            insert_changes($db, 'OSA_Colors', $my_osa_color_id);
        }
        $my_count++;
    }
    $sql = 'UPDATE Quotations' . '   SET status = "Active"' . ' WHERE id = ' . $the_id;
    log_sql('Quotations', 'UPDATE', $sql);
    $db->query($sql);
    insert_changes($db, 'Quotations', $the_id);
    return $my_count;
}
Exemplo n.º 10
0
/**
 *	checkout Piece from Pieces Check Out
 *
 *	$.ajax({ method:'checkout', table:'Pieces', barcode:9...9, ...};
 *
 * @return	string	''
 */
function JKY_checkout_piece($the_data)
{
    $db = Zend_Registry::get('db');
    $my_barcode = get_data($the_data, 'barcode');
    $my_location = get_data($the_data, 'location');
    $my_loadset_id = get_data($the_data, 'loadset_id');
    $my_piece = db_get_row('Pieces', 'id=' . $my_barcode);
    $sql = 'UPDATE LoadSets' . '   SET reserved_pieces = reserved_pieces - 1' . '     , reserved_weight = reserved_weight - ' . $my_piece['checkin_weight'] . '     , checkout_pieces = checkout_pieces + 1' . '     , checkout_weight = checkout_weight + ' . $my_piece['checkin_weight'] . ' WHERE id = ' . $my_loadset_id;
    log_sql('LoadSets', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'LoadSets', $my_loadset_id);
    $my_loadset = db_get_row('LoadSets', 'id=' . $my_loadset_id);
    $sql = 'UPDATE LoadQuotations' . '   SET reserved_pieces = reserved_pieces - 1' . '     , reserved_weight = reserved_weight - ' . $my_piece['checkin_weight'] . '     , checkout_pieces = checkout_pieces + 1' . '     , checkout_weight = checkout_weight + ' . $my_piece['checkin_weight'] . ' WHERE id = ' . $my_loadset['load_quot_id'];
    log_sql('LoadQuotations', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'LoadQuotations', $my_loadset['load_quot_id']);
    $my_loadquot = db_get_row('LoadQuotations', 'id=' . $my_loadset['load_quot_id']);
    $sql = 'UPDATE LoadOuts' . '   SET checkout_at="' . get_time() . '"' . '		, checkout_pieces = checkout_pieces + 1' . '     , checkout_weight = checkout_weight + ' . $my_piece['checkin_weight'] . ' WHERE id = ' . $my_loadquot['loadout_id'];
    log_sql('LoadOuts', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'LoadOuts', $my_loadquot['loadout_id']);
    $sql = 'UPDATE Pieces' . '   SET ' . get_updated() . ',           status="Check Out"' . ',       checkout_by=' . get_session('user_id') . ',       checkout_at="' . get_time() . '"' . ', checkout_location="' . $my_location . '"' . ', load_quot_id= ' . $my_loadquot['id'] . ' WHERE id =' . $my_piece['id'];
    log_sql('Pieces', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Pieces', $my_barcode);
    $sql = 'UPDATE Orders' . '   SET checkout_pieces = checkout_pieces + 1' . '     , checkout_weight = checkout_weight + ' . $my_piece['checkin_weight'] . ' WHERE id = ' . $my_piece['order_id'];
    log_sql('Orders', 'update', $sql);
    $db->query($sql);
    insert_changes($db, 'Orders', $my_piece['order_id']);
    return '';
}