public function post($rest)
 {
     // Originally added by Richard Vinke
     $req = $rest->request();
     $info = $req->post();
     // ToDo Check if loc_code already exists
     // Validate Required Fields
     if (!isset($info['loc_code'])) {
         api_error(412, 'Stock Id is required');
     }
     if (!isset($info['location_name'])) {
         api_error(412, 'Stock Id is required');
     }
     if (!isset($info['delivery_address'])) {
         $info['delivery_address'] = '';
     }
     if (!isset($info['phone'])) {
         $info['phone'] = '';
     }
     if (!isset($info['phone2'])) {
         $info['phone2'] = '';
     }
     if (!isset($info['fax'])) {
         $info['fax'] = '';
     }
     if (!isset($info['email'])) {
         $info['email'] = '';
     }
     if (!isset($info['contact'])) {
         $info['contact'] = '';
     }
     add_item_location($info['loc_code'], $info['location_name'], $info['delivery_address'], $info['phone'], $info['phone2'], $info['fax'], $info['email'], $info['contact']);
     $itm = get_item_location($info['loc_code']);
     if ($itm != null) {
         api_create_response(json_encode($itm));
     } else {
         api_error(500, 'Could Not Save to Database');
     }
 }
Esempio n. 2
0
    if (strlen(db_escape($_POST['loc_code'])) > 7 || empty($_POST['loc_code'])) {
        $input_error = 1;
        display_error(_("The location code must be five characters or less long (including converted special chars)."));
        set_focus('loc_code');
    } elseif (strlen($_POST['location_name']) == 0) {
        $input_error = 1;
        display_error(_("The location name must be entered."));
        set_focus('location_name');
    }
    if ($input_error != 1) {
        if ($selected_id != -1) {
            update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']);
            display_notification(_('Selected location has been updated'));
        } else {
            /*selected_id is null cos no item selected on first time round so must be adding a	record must be submitting new entries in the new Location form */
            add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'], $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], $_POST['contact']);
            display_notification(_('New location has been added'));
        }
        $Mode = 'RESET';
    }
}
function can_delete($selected_id)
{
    if (key_in_foreign_table($selected_id, 'stock_moves', 'loc_code')) {
        display_error(_("Cannot delete this location because item movements have been created using this location."));
        return false;
    }
    if (key_in_foreign_table($selected_id, 'workorders', 'loc_code')) {
        display_error(_("Cannot delete this location because it is used by some work orders records."));
        return false;
    }