Service update
This commit is contained in:
parent
610523d95f
commit
8acbd08293
|
@ -164,6 +164,16 @@ function apiRouter (FastRoute\RouteCollector $r) {
|
|||
apiResponse($services->get($vars['id']));
|
||||
}
|
||||
);
|
||||
$r->addRoute(
|
||||
['POST'],
|
||||
'/services/{id}',
|
||||
function ($vars) {
|
||||
global $services, $users;
|
||||
requireLogin();
|
||||
$users->online_time_update();
|
||||
apiResponse($services->update($vars['id'], $_POST["start"], $_POST["end"], $_POST["code"], $_POST["chief"], $_POST["drivers"], $_POST["crew"], $_POST["place"], $_POST["notes"], $_POST["type"], $users->auth->getUserId()));
|
||||
}
|
||||
);
|
||||
$r->addRoute(
|
||||
['DELETE'],
|
||||
'/services/{id}',
|
||||
|
|
|
@ -459,6 +459,26 @@ class Services {
|
|||
return $serviceId;
|
||||
}
|
||||
|
||||
public function update($id, $start, $end, $code, $chief, $drivers, $crew, $place, $notes, $type, $inserted_by)
|
||||
{
|
||||
$service = $this->db->selectRow(
|
||||
"SELECT `chief`, `drivers`, `crew` FROM `".DB_PREFIX."_services` WHERE `id` = :id",
|
||||
["id" => $id]
|
||||
);
|
||||
$this->decrement_counter($service["chief"].";".$service["drivers"].";".$service["crew"]);
|
||||
|
||||
$this->db->update(
|
||||
DB_PREFIX."_services",
|
||||
["start" => $start, "end" => $end, "code" => $code, "chief" => $chief, "drivers" => $drivers, "crew" => $crew, "place" => $place, "place_reverse" => $this->places->save_place_reverse(explode(";", $place)[0], explode(";", $place)[1]), "notes" => $notes, "type" => $type, "inserted_by" => $inserted_by],
|
||||
["id" => $id]
|
||||
);
|
||||
|
||||
$this->increment_counter($chief.",".$drivers.",".$crew);
|
||||
logger("log_messages.service_updated");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$service = $this->db->selectRow(
|
||||
|
@ -471,7 +491,7 @@ class Services {
|
|||
DB_PREFIX."_services",
|
||||
["id" => $id]
|
||||
);
|
||||
logger("log_messages.service_deleted");
|
||||
logger("log_messages.service_removed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -86,12 +86,12 @@ export class ModalAlertComponent implements OnInit, OnDestroy {
|
|||
this.bsModalRef.hide();
|
||||
this.api.alertsChanged.next();
|
||||
/*
|
||||
this.translate.get('table.service_deleted_successfully').subscribe((res: string) => {
|
||||
this.translate.get('table.service_removed_successfully').subscribe((res: string) => {
|
||||
this.toastr.success(res);
|
||||
});
|
||||
this.loadTableData();
|
||||
}).catch((e) => {
|
||||
this.translate.get('table.service_deleted_error').subscribe((res: string) => {
|
||||
this.translate.get('table.service_removed_error').subscribe((res: string) => {
|
||||
this.toastr.error(res);
|
||||
*/
|
||||
});
|
||||
|
|
|
@ -106,12 +106,12 @@ export class TableComponent implements OnInit, OnDestroy {
|
|||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.api.delete(`services/${id}`).then((response) => {
|
||||
this.translate.get('table.service_deleted_successfully').subscribe((res: string) => {
|
||||
this.translate.get('table.service_removed_successfully').subscribe((res: string) => {
|
||||
this.toastr.success(res);
|
||||
});
|
||||
this.loadTableData();
|
||||
}).catch((e) => {
|
||||
this.translate.get('table.service_deleted_error').subscribe((res: string) => {
|
||||
this.translate.get('table.service_removed_error').subscribe((res: string) => {
|
||||
this.toastr.error(res);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -177,15 +177,19 @@ export class EditServiceComponent implements OnInit {
|
|||
values.drivers = values.drivers.join(";");
|
||||
values.crew = values.crew.join(";");
|
||||
console.log(values);
|
||||
this.api.post("services", values).then((res) => {
|
||||
let submit_url = "services";
|
||||
if(!this.addingService) {
|
||||
submit_url = `services/${this.serviceId}`;
|
||||
}
|
||||
this.api.post(submit_url, values).then((res) => {
|
||||
console.log(res);
|
||||
this.translate.get('edit_service.service_added_successfully').subscribe((res: string) => {
|
||||
this.translate.get(this.addingService ? 'edit_service.service_added_successfully' : 'edit_service.service_updated_successfully').subscribe((res: string) => {
|
||||
this.toastr.success(res);
|
||||
});
|
||||
this.submittingForm = false;
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
this.translate.get('edit_service.service_add_failed').subscribe((res: string) => {
|
||||
this.translate.get(this.addingService ? 'edit_service.service_add_failed' : 'edit_service.service_update_failed').subscribe((res: string) => {
|
||||
this.toastr.error(res);
|
||||
});
|
||||
this.submittingForm = false;
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
"cancel": "Cancel",
|
||||
"remove_service_confirm": "Are you sure you want to remove this service?",
|
||||
"remove_service_confirm_text": "This action cannot be undone.",
|
||||
"service_deleted_successfully": "Service deleted successfully",
|
||||
"service_deleted_error": "Service could not be deleted. Please try again."
|
||||
"service_removed_successfully": "Service deleted successfully",
|
||||
"service_removed_error": "Service could not be deleted. Please try again."
|
||||
},
|
||||
"list": {
|
||||
"your_availability_is": "You are:",
|
||||
|
@ -54,7 +54,9 @@
|
|||
"type_already_exists": "Type already exists",
|
||||
"type_added_successfully": "Type added successfully",
|
||||
"service_added_successfully": "Service added successfully",
|
||||
"service_add_error": "Service could not be added. Please try again"
|
||||
"service_add_error": "Service could not be added. Please try again",
|
||||
"service_updated_successfully": "Service updated successfully",
|
||||
"service_update_error": "Service could not be updated. Please try again"
|
||||
},
|
||||
"update_availability_schedule": "Update availability schedule",
|
||||
"save_changes": "Save changes",
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
"cancel": "Annulla",
|
||||
"remove_service_confirm": "Sei sicuro di voler rimuovere questo intervento?",
|
||||
"remove_service_confirm_text": "Questa operazione non può essere annullata.",
|
||||
"service_deleted_successfully": "Intervento rimosso con successo",
|
||||
"service_deleted_error": "Errore durante la rimozione dell'intervento. Riprova più tardi"
|
||||
"service_removed_successfully": "Intervento rimosso con successo",
|
||||
"service_removed_error": "Errore durante la rimozione dell'intervento. Riprova più tardi"
|
||||
},
|
||||
"list": {
|
||||
"your_availability_is": "Attualmente sei:",
|
||||
|
@ -54,7 +54,9 @@
|
|||
"type_already_exists": "La tipologia è già presente",
|
||||
"type_added_successfully": "Tipologia aggiunta con successo",
|
||||
"service_added_successfully": "Intervento aggiunto con successo",
|
||||
"service_add_error": "Errore durante l'aggiunta dell'intervento. Riprovare più tardi"
|
||||
"service_add_error": "Errore durante l'aggiunta dell'intervento. Riprovare più tardi",
|
||||
"service_updated_successfully": "Intervento modificato con successo",
|
||||
"service_update_error": "Errore durante la modifica dell'intervento. Riprovare più tardi"
|
||||
},
|
||||
"update_availability_schedule": "Aggiorna programmazione disponibilità",
|
||||
"save_changes": "Salva modifiche",
|
||||
|
|
Loading…
Reference in New Issue