Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- /* */
- displayProductsInterface();
- displayCustomerInterface();
- diaplaySuppliersInterface();
- /* */
- insertArticle();
- selectArticle();
- editArticle();
- deleteArticle();
- /* */
- insertSupplier();
- selectSupplier();
- editSupplier();
- deleteSupplier();
- });
- function displayCustomerInterface(){
- $('#manage-customers').on('click',function(e){
- e.preventDefault();
- $.ajax({
- type:'GET',
- url: 'customers.html',
- success: function(interface){
- $('#products,#suppliers').empty();
- $('#customers').html(interface);
- }
- });
- });
- }
- function displayProductsInterface(){
- $('#manage-products').on('click',function(e){
- e.preventDefault();
- $.ajax({
- type:'GET',
- url: 'products.php',
- success: function(interface){
- $('#customers,#suppliers').empty();
- $('#products').html(interface);
- loadProductsList();
- }
- });
- });
- }
- function diaplaySuppliersInterface(){
- $('#manage-suppliers').on('click',function(e){
- e.preventDefault();
- $.ajax({
- type:'GET',
- url: 'suppliers.php',
- cache: false,
- success: function(interface){
- $('#products,#customers').empty();
- $('#suppliers').html(interface);
- loadSuppliersList();
- }
- });
- });
- }
- function loadProductsList(){
- $.ajax({
- type: 'GET',
- url: 'do.php?action=productsList',
- cache: false,
- success: function(response){
- var table = '';
- $.each(JSON.parse(response), function(i, item){
- table = '<tr><td>'+ item.code +'</td><td>'+ item.name +'</td><td>'+ item.brand +'</td><td>'+ item.type +'</td><td>'+ item.pieces +'</td><td>'+ item.price +'</td><td>'+ item.tax +'</td><td>'+ item.supplier +'</td><td>'+ item.shelf +'</td><td>'+ item.note +'</td><td><button type="button" class="btn-link edit" value="?action=selectArticle&id='+ item.id +'" data-toggle="modal" data-target="#editForms">Modifica</button> <button class="btn-link delete" value="'+ item.id +'">Elimina</button></td>';
- $('#productsTable tbody').append(table);
- });
- }
- });
- }
- function loadSuppliersList(){
- $.ajax({
- type: 'GET',
- url: 'do.php?action=suppliersList',
- cache: false,
- success: function(response){
- var table = '';
- $.each(JSON.parse(response), function(i, item){
- table = '<tr><td>'+ item.code +'</td><td>'+ item.name +'</td><td>'+ item.taxid +'</td><td>'+ item.phone +'</td><td>'+ item.fax +'</td><td>'+ item.email +'</td><td><button type="button" class="btn-link edit" value="?action=selectSupplier&id='+ item.id +'" data-toggle="modal" data-target="#editForms">Modifica</button> <button class="btn-link delete" value="'+ item.id +'">Elimina</button></td>';
- $('#suppliersTable tbody').append(table);
- });
- }
- });
- }
- function insertArticle(){
- $(document).on('submit','#productsForm',function(e){
- e.preventDefault();
- var action = 'insertArticle';
- var code = $('#productCode').val();
- var pieces = $('#productPieces').val();
- var brand = $('#productBrand').val();
- var name = $('#productName').val();
- var type = $('#productType').val();
- var supplier = $('#productSupplier').val();
- var shelf = $('#productShelf').val();
- var price = $('#productPrice').val();
- var taxRate = $('#productTaxRate').val();
- var note = $('#productNote').val();
- $.ajax({
- url: 'do.php',
- type: 'POST',
- data: {action:action,code:code,pieces:pieces,name:name,brand:brand,type:type,supplier:supplier,shelf:shelf,price:price,tax:taxRate,note:note},
- cache: false,
- success: function(response){
- console.log(response);
- $('#productsTable tbody').fadeOut()
- .empty()
- .fadeIn('slow',function(){
- loadProductsList();
- });
- }
- });
- });
- }
- function insertSupplier(){
- $(document).on('submit','#supplierForm',function(e){
- e.preventDefault();
- var action = 'insertSupplier';
- var code = $('#supplierCode').val();
- var name = $('#supplierName').val();
- var taxid = $('#supplierTaxNumber').val();
- var phone = $('#supplierPhone').val();
- var fax = $('#supplierFax').val();
- var email = $('#supplierEmail').val();
- var address = $('#supplierAddress').val();
- var cap = $('#supplierCap').val();
- var city = $('#supplierCity').val();
- var province = $('#supplierProvince').val();
- var note = $('#supplierNote').val();
- $.ajax({
- url: 'do.php',
- type: 'POST',
- data: {action:action,code:code,name:name,taxid:taxid,phone:phone,fax:fax,email:email,address:address,cap:cap,city:city,province:province,note:note},
- cache: false,
- success: function(response){
- console.log(response);
- $('#suppliersTable tbody').fadeOut()
- .empty()
- .fadeIn('slow',function(){
- loadSuppliersList();
- });
- }
- });
- });
- }
- function selectArticle(){
- $(document).on('click','button.btn-link.edit',function(e){
- e.preventDefault();
- var href = $(this).val();
- $('.modal-body').empty();
- $.ajax({
- type: 'GET',
- url: 'view/productsForm.html',
- cache: false,
- success: function(interface){
- $('.modal-body').html(interface);
- $.ajax({
- type: 'GET',
- url: 'do.php'+href,
- cache: false,
- success: function(response){
- var data = JSON.parse(response);
- console.log(data);
- $('.article-id').attr('value',data.id);
- $('#editCode').attr('value',data.code);
- $('#editPieces').attr('value',data.pieces);
- $('#editBrand').attr('value',data.brand);
- $('#editName').attr('value',data.name);
- $('#editType').attr('value',data.type);
- $('#editSupplier').attr('value',data.supplier);
- $('#editShelf').attr('value',data.shelf);
- $('#editPrice').attr('value',data.price);
- $('#editTaxRate').attr('value',data.tax);
- $('#editNote').attr('value',data.note);
- }
- });
- }
- });
- });
- }
- function selectSupplier(){
- $(document).on('click','button.btn-link.edit',function(e){
- e.preventDefault();
- var href = $(this).val();
- $('.modal-body').empty();
- $.ajax({
- type: 'GET',
- url: 'view/suppliersForm.html',
- cache: false,
- success: function(interface){
- $('.modal-body').html(interface);
- $.ajax({
- type:'GET',
- url: 'do.php'+href,
- cache: false,
- success: function(response){
- var data = JSON.parse(response);
- $('.supplier-id').attr('value',data.id);
- $('#editCode').attr('value',data.code);
- $('#editName').attr('value',data.name);
- $('#editTaxNumber').attr('value',data.taxid);
- $('#editPhone').attr('value',data.phone);
- $('#editFax').attr('value',data.fax);
- $('#editEmail').attr('value',data.email);
- $('#editAddress').attr('value',data.address);
- $('#editCity').attr('value',data.city);
- $('#editCap').attr('value',data.cap);
- $('#editProvince').attr('value',data.province);
- $('#editNote').attr('value',data.note);
- }
- });
- }
- });
- });
- }
- function editArticle(){
- $(document).on('submit','#editProductForm',function(e){
- e.preventDefault();
- var action = 'editArticle';
- var id = $('.article-id').val();
- var code = $('#editCode').val();
- var pieces = $('#editPieces').val();
- var brand = $('#editBrand').val();
- var name = $('#editName').val();
- var type = $('#editType').val();
- var supplier = $('#editSupplier').val();
- var shelf = $('#editShelf').val();
- var price = $('#editPrice').val();
- var taxRate = $('#editTaxRate').val();
- var note = $('#editNote').val();
- $.ajax({
- type: 'POST',
- url: 'do.php',
- data:{action:action,id:id,code:code,pieces:pieces,name:name,brand:brand,type:type,supplier:supplier,shelf:shelf,price:price,tax:taxRate,note:note},
- cache: false,
- success: function(response){
- console.log(response);
- $('#editForms').modal('hide');
- $('#productsTable tbody').fadeOut()
- .empty()
- .fadeIn('slow',function(){
- loadProductsList();
- });
- }
- });
- });
- }
- function editSupplier(){
- $(document).on('submit','#editSupplierForm',function(e){
- e.preventDefault();
- var action = 'editSupplier';
- var id = $('.supplier-id').val();
- var code = $('#editCode').val();
- var name = $('#editName').val();
- var taxid = $('#editTaxNumber').val();
- var phone = $('#editPhone').val();
- var fax = $('#editFax').val();
- var email = $('#editEmail').val();
- var address = $('#editAddress').val();
- var cap = $('#editCap').val();
- var city = $('#editCity').val();
- var province = $('#editProvince').val();
- var note = $('#editNote').val();
- $.ajax({
- url: 'do.php',
- type: 'POST',
- data: {action:action,id:id,code:code,name:name,taxid:taxid,phone:phone,fax:fax,email:email,address:address,cap:cap,city:city,province:province,note:note},
- cache: false,
- success: function(response){
- console.log(response);
- $('#editForms').modal('hide');
- $('#suppliersTable tbody').fadeOut()
- .empty()
- .fadeIn('slow',function(){
- loadSuppliersList();
- });
- }
- });
- });
- }
- function deleteArticle(){
- $(document).on('click','button.btn-link.delete',function(e){
- e.preventDefault();
- var action = 'deleteArticle';
- var id = $(this).val();
- $.ajax({
- type: 'POST',
- data: {action:action,id:id},
- url: 'do.php',
- cache: false,
- success: function(response){
- $('#productsTable tbody').fadeOut()
- .empty()
- .fadeIn('fast',function(){
- loadProductsList();
- });
- }
- });
- });
- }
- function deleteSupplier(){
- $(document).on('click','button.btn-link.delete',function(e){
- e.preventDefault();
- var action = 'deleteSupplier';
- var id = $(this).val();
- $.ajax({
- type: 'POST',
- data: {action:action,id:id},
- url: 'do.php',
- cache: false,
- success: function(response){
- $('#suppliersTable tbody').fadeOut()
- .empty()
- .fadeIn('slow',function(){
- loadSuppliersList();
- });
- }
- });
- });
- }
Add Comment
Please, Sign In to add comment