Esempio n. 1
0
        public int MakeVoucher(Voucher voucher)
        {
            SSGetService    getService = new SSGetService();
            VoucherCategory category   = getService.getVoucherByName(voucher.type);

            if (category.name != null)
            {
                DataTable data = service.get("select * from ss_account");
                if (data.Rows.Count > 0)
                {
                    DataRow row            = data.Rows[0];
                    int     balance        = row.Field <int>("balance");
                    int     previusBalance = balance;

                    if (balance >= voucher.amount)
                    {
                        balance = balance - voucher.amount;
                        using (SqlCommand command = new SqlCommand("update ss_account set balance=@balance, previous_balance=@previous_balance"))
                        {
                            command.Parameters.AddWithValue("@balance", balance);
                            command.Parameters.AddWithValue("@previous_balance", previusBalance);

                            if (service.execute(command) > 0)
                            {
                                User user = app.getSession();
                                using (SqlCommand addCommand = new SqlCommand("INSERT INTO ss_vouchers(user_id,amount,amount_in_words,type,description)VALUES(@user_id,@amount,@amount_in_words,@type,@description)"))
                                {
                                    addCommand.Parameters.AddWithValue("@user_id", user.id);
                                    addCommand.Parameters.AddWithValue("@amount", voucher.amount);
                                    addCommand.Parameters.AddWithValue("@amount_in_words", app.toWordsOf(voucher.amount));
                                    addCommand.Parameters.AddWithValue("@type", voucher.type);
                                    addCommand.Parameters.AddWithValue("@description", voucher.description);

                                    return(service.execute(addCommand));
                                }
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                    }
                    else
                    {
                        return(-402);
                    }
                }
                else
                {
                    return(-403);
                }
            }
            else
            {
                return(-404);
            }
        }
Esempio n. 2
0
        public int addUser(User user)
        {
            SSGetService getService = new SSGetService();

            User numberCheck   = getService.getUserByMobileNumber(user.mobile_number);
            User usernameCheck = getService.getUserByUsername(user.username);

            if (usernameCheck.username == null)
            {
                if (numberCheck.mobile_number == null)
                {
                    using (SqlCommand command = new SqlCommand("INSERT INTO ss_users(bid,name, username, password, mobile_number,picture)VALUES(@bid,@name,@username,@password, @mobile_number,@picture)"))
                    {
                        command.Parameters.AddWithValue("@bid", user.bid);
                        command.Parameters.AddWithValue("@name", user.name);
                        command.Parameters.AddWithValue("@username", user.username);
                        command.Parameters.AddWithValue("@password", user.password);
                        command.Parameters.AddWithValue("@mobile_number", user.mobile_number);
                        if (user.picture != null)
                        {
                            command.Parameters.Add("@picture", SqlDbType.Image, user.picture.Length).Value = user.picture;
                        }


                        int response = service.execute(command);
                        if (response > 0)
                        {
                            this.addLog(new Log()
                            {
                                type        = "Add User",
                                statement   = command.CommandText,
                                description = "Created user " + user.name,
                            });
                        }

                        return(response);
                    }
                }
                else
                {
                    return(-3);
                }
            }
            else
            {
                return(-2);
            }
        }
Esempio n. 3
0
        public int updateLastLoginDate(User user)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();


            using (SqlCommand command = new SqlCommand("UPDATE ss_users SET login_date=CURRENT_TIMESTAMP WHERE id=" + user.id + ""))
            {
                int response = service.execute(command);
                addService.addLog(new Log()
                {
                    type        = "User logged in",
                    statement   = user.username,
                    description = "User logged in " + user.name,
                });
                return(response);
            }
        }
Esempio n. 4
0
        public int updateBatchBalance(Batch batch)
        {
            SSGetService getService = new SSGetService();
            SSAddService addService = new SSAddService();

            using (SqlCommand command = new SqlCommand("UPDATE ss_batches SET balance=@balance, sold=@sold WHERE id=" + batch.id + ""))
            {
                command.Parameters.AddWithValue("@balance", batch.balance);
                command.Parameters.AddWithValue("@sold", batch.sold);
                int response = service.execute(command);
                if (response > 0)
                {
                    addService.addLog(new Log()
                    {
                        type        = "Updated batch  balance",
                        statement   = command.CommandText,
                        description = "Updated [" + batch.id + "] Batch",
                    });
                }
                return(response);
            }
        }
Esempio n. 5
0
        public int addDebtor(Customer customer, int amount)
        {
            SSGetService getService = new SSGetService();

            if (customer.id != -1)
            {
                Debtor debtor = getService.getDebtorByIdEvenIfZero(customer.id);
                if (debtor.name == null)
                {
                    //add the debt if not there
                    using (SqlCommand command = new SqlCommand("INSERT INTO ss_debtors(cid,name,amount,last_modified_date)VALUES(@cid,@name,@amount,getdate())"))
                    {
                        command.Parameters.AddWithValue("@cid", customer.id);
                        command.Parameters.AddWithValue("@name", customer.name);
                        command.Parameters.AddWithValue("@amount", amount);
                        int response = service.execute(command);
                        return(response);
                    }
                }
                else
                {
                    //increase the debit if already there
                    amount = debtor.amount + amount;
                    using (SqlCommand command = new SqlCommand("UPDATE ss_debtors SET amount=@amount,last_modified_date=getdate() WHERE cid=" + debtor.cid))
                    {
                        command.Parameters.AddWithValue("@amount", amount);
                        int response = service.execute(command);
                        return(response);
                    }
                }
            }
            else
            {
                return(-404);
            }
        }
Esempio n. 6
0
        public void buildSalesDropdown(Form currentForm, Object sender, Panel panel, string source)
        {
            TextBox      textBox    = (sender as TextBox);
            SSGetService getService = new SSGetService();

            currentTextBox = textBox;


            if (!listedItems.Contains(textBox.Text) && textBox.Text.Length > 1)
            {
                customDropdown.HideSelection = false;
                customDropdown.Margin        = new Padding(5);
                customDropdown.Size          = new Size(panel.Width, 97);
                customDropdown.Sorting       = SortOrder.Ascending;
                customDropdown.TabIndex      = 58;
                customDropdown.TileSize      = new Size(panel.Width, 25);
                customDropdown.UseCompatibleStateImageBehavior = false;
                customDropdown.View                  = View.Tile;
                customDropdown.Location              = new Point(panel.Location.X + 18, panel.Location.Y + (panel.Height * 3) - 11);
                customDropdown.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(onSelectedIndexChanged);
                customDropdown.MouseLeave           += new EventHandler(onMouseLeave);
                customDropdown.Hide();


                if (textBox.Text != "" && textBox.Text != null)
                {
                    try
                    {
                        DataTable data = getService.searchDataFrom(this.objects[source], textBox.Text);

                        if (data.Rows.Count > 0)
                        {
                            customDropdown.Clear();
                            currentForm.Controls.Add(customDropdown);
                            customDropdown.BringToFront();
                            customDropdown.Show();

                            foreach (DataRow row in data.Rows)
                            {
                                string name = row.Field <string>("name");
                                listedItems.Add(name);
                                customDropdown.Items.Add(name);
                            }
                        }
                        else
                        {
                            customDropdown.Hide();
                            currentForm.Controls.Remove(customDropdown);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.showError(ex.Message);
                    }
                }
                else
                {
                    customDropdown.Hide();
                    currentForm.Controls.Remove(customDropdown);
                }
            }
            else
            {
                customDropdown.Hide();
                currentForm.Controls.Remove(customDropdown);
            }
        }
Esempio n. 7
0
        public int addPayment(Payment payment)
        {
            SSGetService    getService    = new SSGetService();
            SSUpdateService updateService = new SSUpdateService();

            User     user     = app.getSession();
            Customer customer = getService.getCustomerByName(payment.customer_name);

            if (customer.name != null)
            {
                if (payment.transaction_type == "Payment")
                {
                    Debtor debtor = getService.getDebtorById(customer.id);
                    if (debtor.name != null)
                    {
                        int clearedAmount;
                        int outstanding;

                        clearedAmount = outstanding = 0;

                        //perform the caculation
                        if (payment.transaction_amount >= debtor.amount)
                        {
                            clearedAmount = (debtor.amount);
                            outstanding   = (debtor.amount - payment.transaction_amount);
                        }
                        else
                        {
                            clearedAmount = payment.transaction_amount;
                            outstanding   = (debtor.amount - payment.transaction_amount);
                        }


                        //add payment entry
                        using (SqlCommand command = new SqlCommand("INSERT INTO ss_payments(cid,user_id,customer_name,transaction_amount,cleared_amount,amount_in_words,transaction_type,payment_mode,description)VALUES(@cid,@user_id,@customer_name,@transaction_amount,@cleared_amount,@amount_in_words,@transaction_type,@payment_mode,@description)"))
                        {
                            command.Parameters.AddWithValue("@cid", customer.id);
                            command.Parameters.AddWithValue("@user_id", user.id);
                            command.Parameters.AddWithValue("@customer_name", customer.name);
                            command.Parameters.AddWithValue("@transaction_amount", payment.transaction_amount);
                            command.Parameters.AddWithValue("@cleared_amount", clearedAmount);
                            command.Parameters.AddWithValue("@amount_in_words", app.toWordsOf(payment.transaction_amount));
                            command.Parameters.AddWithValue("@transaction_type", payment.transaction_type);
                            command.Parameters.AddWithValue("@payment_mode", payment.payment_mode);
                            command.Parameters.AddWithValue("@description", payment.description);

                            if (service.execute(command) > 0)
                            {
                                if (outstanding < 0)
                                {
                                    //update customer balance if any
                                    if (customer.account_balance > 0 || customer.account_balance < 0)
                                    {
                                        customer.account_balance += Math.Abs(outstanding);
                                    }
                                    else
                                    {
                                        customer.account_balance = Math.Abs(outstanding);
                                    }

                                    updateService.updateCustomerBalance(customer);
                                }

                                //update debtor balance
                                if (clearedAmount >= debtor.amount)
                                {
                                    debtor.amount = 0;
                                }
                                else
                                {
                                    debtor.amount = outstanding;
                                }


                                DataTable data = service.get("select * from ss_account");
                                if (data.Rows.Count > 0)
                                {
                                    DataRow row            = data.Rows[0];
                                    int     balance        = row.Field <int>("balance");
                                    int     previusBalance = balance;

                                    balance = balance + payment.transaction_amount;
                                    using (SqlCommand updateCommand = new SqlCommand("update ss_account set balance=@balance, previous_balance=@previous_balance"))
                                    {
                                        updateCommand.Parameters.AddWithValue("@balance", balance);
                                        updateCommand.Parameters.AddWithValue("@previous_balance", previusBalance);

                                        if (service.execute(updateCommand) > 0)
                                        {
                                            return(updateService.updateDebtorBalance(debtor));
                                        }
                                        else
                                        {
                                            return(-1);
                                        }
                                    }
                                }
                                else
                                {
                                    return(-1);
                                }
                            }

                            else
                            {
                                return(-1);
                            }
                        }
                    }
                    else
                    {
                        if (payment.description == "Purchasing Payment")
                        {
                            using (SqlCommand command = new SqlCommand("INSERT INTO ss_payments(cid,user_id,customer_name,transaction_amount,cleared_amount,amount_in_words,transaction_type,payment_mode,description)VALUES(@cid,@user_id,@customer_name,@transaction_amount,@cleared_amount,@amount_in_words,@transaction_type,@payment_mode,@description)"))
                            {
                                command.Parameters.AddWithValue("@cid", customer.id);
                                command.Parameters.AddWithValue("@user_id", user.id);
                                command.Parameters.AddWithValue("@customer_name", customer.name);
                                command.Parameters.AddWithValue("@transaction_amount", payment.transaction_amount);
                                command.Parameters.AddWithValue("@cleared_amount", payment.cleared_amount);
                                command.Parameters.AddWithValue("@amount_in_words", app.toWordsOf(payment.transaction_amount));
                                command.Parameters.AddWithValue("@transaction_type", payment.transaction_type);
                                command.Parameters.AddWithValue("@payment_mode", payment.payment_mode);
                                command.Parameters.AddWithValue("@description", payment.description);

                                if (service.execute(command) > 0)
                                {
                                    DataTable data = service.get("select * from ss_account");
                                    if (data.Rows.Count > 0)
                                    {
                                        DataRow row            = data.Rows[0];
                                        int     balance        = row.Field <int>("balance");
                                        int     previusBalance = balance;

                                        balance = balance + payment.transaction_amount;
                                        using (SqlCommand updateCommand = new SqlCommand("update ss_account set balance=@balance, previous_balance=@previous_balance"))
                                        {
                                            updateCommand.Parameters.AddWithValue("@balance", balance);
                                            updateCommand.Parameters.AddWithValue("@previous_balance", previusBalance);

                                            return(service.execute(updateCommand));
                                        }
                                    }
                                    else
                                    {
                                        return(-1);
                                    }
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                        }
                        else
                        {
                            return(-202);
                        }
                    }
                }
                else
                {
                    int clearedAmount = 0;
                    int outstanding   = 0;
                    if (payment.payment_mode == "Credit")
                    {
                        Debtor debtor = getService.getDebtorByIdEvenIfZero(customer.id);
                        if (debtor.name != null)
                        {
                            debtor.amount += payment.transaction_amount;
                            int res = updateService.updateDebtorBalance(debtor);
                        }
                        else
                        {
                            this.addDebtor(customer, payment.transaction_amount);
                        }
                    }
                    else
                    {
                        Debtor debtor = getService.getDebtorByIdEvenIfZero(customer.id);
                        if (debtor.name != null)
                        {
                            if (debtor.amount >= payment.transaction_amount)
                            {
                                debtor.amount = (debtor.amount - payment.transaction_amount);
                                clearedAmount = payment.transaction_amount;
                                updateService.updateDebtorBalance(debtor);
                            }
                            else
                            {
                                clearedAmount = debtor.amount;
                                outstanding   = (payment.transaction_amount - debtor.amount);
                                debtor.amount = 0;
                                updateService.updateDebtorBalance(debtor);

                                if (outstanding > 0)
                                {
                                    customer.account_balance += outstanding;
                                    updateService.updateCustomerBalance(customer);
                                }
                            }
                        }
                        else
                        {
                            customer.account_balance += payment.transaction_amount;
                            updateService.updateCustomerBalance(customer);
                        }
                    }

                    using (SqlCommand command = new SqlCommand("INSERT INTO ss_adjustments(cid,customer_name,transaction_amount,cleared_amount,transaction_type,payment_mode,description)VALUES(@cid,@customer_name,@transaction_amount,@cleared_amount,@transaction_type,@payment_mode,@description)"))
                    {
                        command.Parameters.AddWithValue("@cid", customer.id);
                        command.Parameters.AddWithValue("@customer_name", customer.name);
                        command.Parameters.AddWithValue("@transaction_amount", payment.transaction_amount);
                        command.Parameters.AddWithValue("@cleared_amount", clearedAmount);
                        command.Parameters.AddWithValue("@transaction_type", payment.transaction_type);
                        command.Parameters.AddWithValue("@payment_mode", payment.payment_mode);
                        command.Parameters.AddWithValue("@description", payment.description);


                        DataTable data = service.get("select * from ss_account");
                        if (data.Rows.Count > 0)
                        {
                            DataRow row            = data.Rows[0];
                            int     balance        = row.Field <int>("balance");
                            int     previusBalance = balance;

                            if (payment.payment_mode == "Credit")
                            {
                                balance = balance + payment.transaction_amount;
                            }


                            using (SqlCommand updateCommand = new SqlCommand("update ss_account set balance=@balance, previous_balance=@previous_balance, last_modified_date=getdate()"))
                            {
                                updateCommand.Parameters.AddWithValue("@balance", balance);
                                updateCommand.Parameters.AddWithValue("@previous_balance", previusBalance);

                                if (service.execute(updateCommand) > 0)
                                {
                                    return(service.execute(command));
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                }
            }
            else
            {
                return(-404);
            }
        }
Esempio n. 8
0
        public int addStock(Stock stock)
        {
            SSGetService    getService    = new SSGetService();
            SSUpdateService updateService = new SSUpdateService();

            Product existingProduct = getService.getProductByName(stock.name);

            if (existingProduct.name != null)
            {
                Location existingLocation = getService.getLocationByName(stock.location);
                if (existingLocation.name != null)
                {
                    string    batchName;
                    string    batchFormat = DateTime.Now.ToString("MMyyyy");
                    DataTable batchData   = getService.getDataWithFilter(app.objects["batches"], " name like '%" + batchFormat + "' order by created_date desc");
                    if (batchData.Rows.Count > 0)
                    {
                        DataRow row  = batchData.Rows[0];
                        string  name = row.Field <string>("name");
                        string  val  = name.Substring(name.IndexOf('B') + 1, name.IndexOf('-') - 1);
                        if (app.isAllDigits(val))
                        {
                            batchName = "B" + (int.Parse(val) + 1) + "-" + batchFormat;
                        }
                        else
                        {
                            batchName = "";
                        }
                    }
                    else
                    {
                        batchName = "B1-" + batchFormat;
                    }
                    string batchKey = app.generateId(20);

                    if (batchName != null && batchName != "")
                    {
                        using (SqlCommand batchCommand = new SqlCommand("INSERT INTO ss_batches(name,reference_key,pid,total,balance,sold)VALUES(@name,@reference_key,@pid,@total,@balance,@sold)"))
                        {
                            batchCommand.Parameters.AddWithValue("@name", batchName);
                            batchCommand.Parameters.AddWithValue("@reference_key", batchKey);
                            batchCommand.Parameters.AddWithValue("@pid", existingProduct.id);
                            batchCommand.Parameters.AddWithValue("@total", stock.quantity);
                            batchCommand.Parameters.AddWithValue("@balance", stock.quantity);
                            batchCommand.Parameters.AddWithValue("@sold", 0);

                            int batchResponse = service.execute(batchCommand);
                            if (batchResponse > 0)
                            {
                                Batch batch = getService.getBatchByKey(batchKey);
                                if (batch.key != null)
                                {
                                    using (SqlCommand command = new SqlCommand("INSERT INTO ss_stocks(pid,bid,quantity,cost,description,last_modified_date)VALUES(@pid,@bid,@quantity,@cost,@description, getdate())"))
                                    {
                                        command.Parameters.AddWithValue("@pid", existingProduct.id);
                                        command.Parameters.AddWithValue("@bid", batch.id);
                                        command.Parameters.AddWithValue("@quantity", stock.quantity);
                                        command.Parameters.AddWithValue("@cost", stock.cost);
                                        command.Parameters.AddWithValue("@description", stock.description);
                                        int response = service.execute(command);
                                        if (response > 0)
                                        {
                                            return(response);
                                        }
                                        else
                                        {
                                            return(-1);
                                        }
                                    }
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                            else
                            {
                                return(-402);
                            }
                        }
                    }
                    else
                    {
                        return(-500);
                    }
                }
                else
                {
                    return(-404);
                }
            }
            else
            {
                return(-403);
            }
        }
Esempio n. 9
0
        public int addBusiness(Business business)
        {
            SSGetService    getService    = new SSGetService();
            SSAddService    addService    = new SSAddService();
            SSRemoteService remoteService = new SSRemoteService();
            SSUpdateService updateService = new SSUpdateService();

            //Business existingBusiness = getService.getBusinessByName(business.business_name);
            //if (existingBusiness.name == null)
            //{

            //    Key key = remoteService.getProductKey(business.product_key);
            //    if (key.product_key != null)
            //    {
            //        if (key.status == "PA")
            //        {
            business.status = "AC";
            //update remote productKet status

            //done

            using (SqlCommand command = new SqlCommand("INSERT INTO ss_business(name,motto,address,telephone,email_address,product_key,machine_name,status,logo)VALUES(@name,@motto,@address,@telephone,@email_address,@product_key,@machine_name,@status,@logo)"))
            {
                command.Parameters.AddWithValue("@name", business.business_name);
                command.Parameters.AddWithValue("@motto", business.motto.ToString().ToUpper());
                command.Parameters.AddWithValue("@address", business.address);
                command.Parameters.AddWithValue("@telephone", business.telephone);
                command.Parameters.AddWithValue("@email_address", business.email_address);
                command.Parameters.AddWithValue("@product_key", business.product_key);
                command.Parameters.AddWithValue("@machine_name", business.machine_name);
                command.Parameters.AddWithValue("@status", business.status);
                if (business.logo != null)
                {
                    command.Parameters.Add("@logo", SqlDbType.Image, business.logo.Length).Value = business.logo;
                }

                int response1 = service.execute(command);
                int response2 = 1;             //service.remoteExecute(command);
                if (response1 > 0 && response2 > 0)
                {
                    Business currentBusiness = getService.getBusinessByName(business.business_name);
                    if (currentBusiness.business_name != null)
                    {
                        //register admin user


                        User user = new User()
                        {
                            bid           = currentBusiness.id,
                            name          = business.name,
                            username      = business.username,
                            password      = business.password,
                            mobile_number = business.telephone,
                            role          = "All",
                        };
                        if (business.logo != null)
                        {
                            user.picture = business.logo;
                        }


                        int res = addService.addUser(user);
                        if (res > 0)
                        {
                            this.addLog(new Log()
                            {
                                type        = "Add Business",
                                statement   = command.CommandText,
                                description = "Added Business" + business.business_name,
                            });
                            return(res);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else
                {
                    return(-3);
                }
            }
            //        }
            //        else
            //        {
            //            return 201;
            //        }
            //    }
            //    else
            //    {
            //        return -404;
            //    }
            //}
            //else
            //{
            //    return -200;
            //}
        }
Esempio n. 10
0
        public int addSale(Sale sale)
        {
            SSGetService getService = new SSGetService();
            User         user       = app.getSession();
            DataTable    cartData   = getService.getCartData(user);

            if (cartData.Rows.Count > 0)
            {
                using (SqlCommand command = new SqlCommand("INSERT INTO ss_sales(pids,user_id,customer_id,item_count,customer_name,location,total,discount,outstanding_balance,cleared_amount,part_payment,payment_method,bank_name)VALUES(@pids,@user_id,@customer_id,@item_count,@customer_name,@location,@total,@discount,@outstanding_balance,@cleared_amount,@part_payment,@payment_method,@bank_name)"))
                {
                    command.Parameters.AddWithValue("@pids", sale.products);
                    command.Parameters.AddWithValue("@user_id", user.id);
                    command.Parameters.AddWithValue("@customer_id", sale.cid);
                    command.Parameters.AddWithValue("@customer_name", sale.customer_name);
                    command.Parameters.AddWithValue("@item_count", sale.item_count);
                    command.Parameters.AddWithValue("@location", sale.product_location);
                    command.Parameters.AddWithValue("@total", sale.total);
                    command.Parameters.AddWithValue("@discount", sale.discount);
                    command.Parameters.AddWithValue("@outstanding_balance", sale.outstanding_balance);
                    command.Parameters.AddWithValue("@cleared_amount", sale.cleared_amount);
                    command.Parameters.AddWithValue("@part_payment", sale.part_payment);
                    command.Parameters.AddWithValue("@payment_method", sale.payment_method);
                    command.Parameters.AddWithValue("@bank_name", sale.bank_name);

                    int response = service.execute(command);
                    if (response > 0)
                    {
                        using (SqlCommand salesDetailsCommand = new SqlCommand("INSERT INTO ss_sale_details(user_id, tid,pid,bid,product_name,quantity,unit_price,unit_discount,location,total,transaction_date)SELECT user_id, (select top 1 id from ss_sales l where l.user_id = " + user.id + " and l.customer_name = '" + sale.customer_name + "' order by l.transaction_date desc) tid, pid, bid, product_name, quantity, unit_price, unit_discount, location, total, created_date FROM ss_cart where user_id = " + user.id))
                        {
                            if (service.execute(salesDetailsCommand) > 0)
                            {
                                using (SqlCommand cartResetCommand = new SqlCommand("DELETE ss_cart WHERE user_id=" + user.id))
                                {
                                    if (sale.payment_method == "Credit")
                                    {
                                        Customer customer = new Customer()
                                        {
                                            id   = sale.cid,
                                            name = sale.customer_name
                                        };
                                        this.addDebtor(customer, sale.total);
                                    }

                                    return(service.execute(cartResetCommand));
                                };
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            else
            {
                return(-404);
            }
        }